summaryrefslogtreecommitdiff
path: root/src/time/asctime_s.c
blob: 879859066b6bd374131b22de8ed17c3b1ebe2e64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <time.h>
#include <stdio.h>

/** convert broken down time to string **/
errno_t asctime_s(char *s, rsize_t maxsize, const struct tm * timeptr)
{
	__C_EXT(1, 201112L);
	static const char days[7][3] = {
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
	};
	static const char months[12][3] = {
		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
	};
	static char result[26];

	sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
		days[timeptr->tm_wday], months[timeptr->tm_mon],
		timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min,
		timeptr->tm_sec, timeptr->tm_year + 1900);
	return result;
}

/***
The fn(asctime) function converts the time specified at arg(timeptr) to a string
in the format string(DDD MMM dd hh:mm:ss yyyy\n\0), where str(DDD) is the
three-character abbreviated day of the week, str(MMM) is the three-character
abbreviated month, string(dd) is the day of the month, str(hh) is the hour of
the day (in the range (0,23)), str(mm) is the minute of the hour (in the range
(0,59)), str(ss) is the second of the minute (in the range (0,61)), and
str(yyyy) is the year.
***/

/* UNSPECIFIED: - */
/* UNDEFINED: - */
/* IMPLEMENTATION: - */
/* LOCALE: - */

/* RETURN: a pointer to the string */

/*
CEXT1(201112)
*/