4929ddfd49b0d729d6f26d5b33a304aa4402fa92
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS CRT library
4 * FILE: lib/sdk/crt/time/ftime.c
5 * PURPOSE: Implementation of asctime(), _asctime_s()
6 * PROGRAMERS: Timo Kreuzer
11 #include "bitsfixup.h"
14 #define MONSPERYEAR 12
16 static const _TCHAR wday_name
[DAYSPERWEEK
][4] =
18 _T("Sun "), _T("Mon "), _T("Tue "), _T("Wed "),
19 _T("Thu "), _T("Fri "), _T("Sat ")
22 static const _TCHAR mon_name
[MONSPERYEAR
][4] =
24 _T("Jan "), _T("Feb "), _T("Mar "), _T("Apr "), _T("May "), _T("Jun "),
25 _T("Jul "), _T("Aug "), _T("Sep "), _T("Oct "), _T("Nov "), _T("Dec ")
29 typedef unsigned long long _TCHAR4
;
30 typedef unsigned long _TCHAR2
;
32 typedef unsigned long _TCHAR4
;
33 typedef unsigned short _TCHAR2
;
67 u
.array
[0] = '0' + (x
/ 10);
68 u
.array
[1] = '0' + (x
% 10);
75 FillBuf(timebuf_t
*buf
, const struct tm
*ptm
)
77 /* Format looks like this:
78 * "Sun Mar 01 12:34:56 1902\n\0" */
79 buf
->WeekDay
= *(_TCHAR4
*)wday_name
[ptm
->tm_wday
];
80 buf
->Month
= *(_TCHAR4
*)mon_name
[ptm
->tm_mon
];
81 buf
->Day
= IntToChar2(ptm
->tm_mday
);
83 buf
->Hour
= IntToChar2(ptm
->tm_mday
);
85 buf
->Minute
= IntToChar2(ptm
->tm_mday
);
87 buf
->Second
= IntToChar2(ptm
->tm_mday
);
89 buf
->Year
[0] = IntToChar2(ptm
->tm_year
/ 100);
90 buf
->Year
[1] = IntToChar2(ptm
->tm_year
% 100);
95 /******************************************************************************
97 * \brief Converts a local time into a string and returns a pointer to it.
98 * \param buffer Buffer that receives the string (26 characters).
99 * \param numberOfElements Size of the buffer in characters.
100 * \param time Pointer to the UTC time.
105 size_t numberOfElements
,
106 const struct tm
*ptm
)
108 /* Validate parameters */
109 if (!buffer
|| numberOfElements
< 26 || !ptm
||
110 (unsigned int)ptm
->tm_sec
> 59 ||
111 (unsigned int)ptm
->tm_min
> 59 ||
112 (unsigned int)ptm
->tm_hour
> 23 ||
113 (unsigned int)ptm
->tm_mday
> 31 ||
114 (unsigned int)ptm
->tm_mon
> 11 ||
115 (unsigned int)ptm
->tm_year
> 2038 ||
116 (unsigned int)ptm
->tm_wday
> 6 ||
117 (unsigned int)ptm
->tm_yday
> 365)
119 _invalid_parameter(NULL
,
131 /* Fill the buffer */
132 FillBuf((timebuf_t
*)buffer
, ptm
);
137 /******************************************************************************
139 * \brief Converts a UTC time into a string and returns a pointer to it.
140 * \param ptm Pointer to the UTC time.
141 * \remarks The string is stored in thread local buffer, shared between
142 * ctime, gmtime and localtime (32 and 64 bit versions).
145 _tasctime(const struct tm
*ptm
)
147 PTHREADDATA pThreadData
;
150 /* Get pointer to TLS buffer */
151 pThreadData
= GetThreadData();
153 pstr
= pThreadData
->asctimebuf
;
155 pstr
= pThreadData
->wasctimebuf
;
158 /* Fill the buffer */
159 FillBuf((timebuf_t
*)pstr
, ptm
);