]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/time.h
Add Socket Libraries.
[mirror_edk2.git] / StdLib / Include / time.h
1 /** @file
2 The header <time.h> defines two macros, and declares several types and
3 functions for manipulating time. Many functions deal with a calendar time
4 that represents the current date (according to the Gregorian calendar) and
5 time. Some functions deal with local time, which is the calendar time
6 expressed for some specific time zone, and with Daylight Saving Time, which
7 is a temporary change in the algorithm for determining local time. The local
8 time zone and Daylight Saving Time are implementation-defined.
9
10 The macros defined are NULL; and CLOCKS_PER_SEC which expands to an
11 expression with type clock_t (described below) that is the number per second
12 of the value returned by the clock function.
13
14 The types declared are size_t along with clock_t and time_t which are
15 arithmetic types capable of representing times; and struct tm which holds
16 the components of a calendar time, called the broken-down time.
17
18 The range and precision of times representable in clock_t and time_t are
19 implementation-defined. The tm structure shall contain at least the following
20 members, in any order. The semantics of the members and their normal ranges
21 are expressed in the comments.
22 - int tm_sec; // seconds after the minute - [0, 60]
23 - int tm_min; // minutes after the hour - [0, 59]
24 - int tm_hour; // hours since midnight - [0, 23]
25 - int tm_mday; // day of the month - [1, 31]
26 - int tm_mon; // months since January - [0, 11]
27 - int tm_year; // years since 1900
28 - int tm_wday; // days since Sunday - [0, 6]
29 - int tm_yday; // days since January 1 - [0, 365]
30 - int tm_isdst; // Daylight Saving Time flag
31
32 The value of tm_isdst is positive if Daylight Saving Time is in effect, zero
33 if Daylight Saving Time is not in effect, and negative if the information
34 is not available.
35
36 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
37 This program and the accompanying materials are licensed and made available under
38 the terms and conditions of the BSD License that accompanies this distribution.
39 The full text of the license may be found at
40 http://opensource.org/licenses/bsd-license.
41
42 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
43 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
44
45 **/
46 #ifndef _TIME_H
47 #define _TIME_H
48 #include <sys/EfiCdefs.h>
49
50 #define CLOCKS_PER_SEC __getCPS()
51
52 #ifdef _EFI_SIZE_T_
53 typedef _EFI_SIZE_T_ size_t;
54 #undef _EFI_SIZE_T_
55 #undef _BSD_SIZE_T_
56 #endif
57
58 /** An arithmetic type capable of representing values returned by clock(); **/
59 #ifdef _EFI_CLOCK_T
60 typedef _EFI_CLOCK_T clock_t;
61 #undef _EFI_CLOCK_T
62 #endif
63
64 /** An arithmetic type capable of representing values returned as calendar time
65 values, such as that returned by mktime();
66 **/
67 #ifdef _EFI_TIME_T
68 typedef _EFI_TIME_T time_t;
69 #undef _EFI_TIME_T
70 #endif
71
72 /** Value added to tm_year to get the full year value. TM_YEAR_BASE + 110 --> 2010
73 **/
74 #define TM_YEAR_BASE 1900
75
76 /** Values for the tm_wday member of struct tm.
77 @{
78 **/
79 #define TM_SUNDAY 0
80 #define TM_MONDAY 1
81 #define TM_TUESDAY 2
82 #define TM_WEDNESDAY 3
83 #define TM_THURSDAY 4
84 #define TM_FRIDAY 5
85 #define TM_SATURDAY 6
86 /** @} **/
87
88 /** Values for the tm_mon member of struct tm.
89 @{
90 **/
91 #define TM_JANUARY 0
92 #define TM_FEBRUARY 1
93 #define TM_MARCH 2
94 #define TM_APRIL 3
95 #define TM_MAY 4
96 #define TM_JUNE 5
97 #define TM_JULY 6
98 #define TM_AUGUST 7
99 #define TM_SEPTEMBER 8
100 #define TM_OCTOBER 9
101 #define TM_NOVEMBER 10
102 #define TM_DECEMBER 11
103 /** @} **/
104
105 /** A structure holding the components of a calendar time, called the
106 broken-down time. The first nine (9) members are as mandated by the
107 C95 standard. Additional fields have been added for EFI support.
108 **/
109 struct tm {
110 int tm_year; // years since 1900
111 int tm_mon; // months since January [0, 11]
112 int tm_mday; // day of the month [1, 31]
113 int tm_hour; // hours since midnight [0, 23]
114 int tm_min; // minutes after the hour [0, 59]
115 int tm_sec; // seconds after the minute [0, 60]
116 int tm_wday; // days since Sunday [0, 6]
117 int tm_yday; // days since January 1 [0, 365]
118 int tm_isdst; // Daylight Saving Time flag
119 int tm_zoneoff; // EFI TimeZone offset, -1440 to 1440 or 2047
120 int tm_daylight; // EFI Daylight flags
121 UINT32 tm_Nano; // EFI Nanosecond value
122 };
123
124 /* ############### Time Manipulation Functions ########################## */
125
126 /** The clock function determines the processor time used.
127
128 @return The clock function returns the implementation's best
129 approximation to the processor time used by the program since the
130 beginning of an implementation-defined era related only to the
131 program invocation. To determine the time in seconds, the value
132 returned by the clock function should be divided by the value of
133 the macro CLOCKS_PER_SEC. If the processor time used is not
134 available or its value cannot be represented, the function
135 returns the value (clock_t)(-1).
136
137 On IA32 or X64 platforms, the value returned is the number of
138 CPU TimeStamp Counter ticks since the appliation started.
139 **/
140 clock_t clock(void);
141
142 /**
143 **/
144 double difftime(time_t time1, time_t time0);
145
146 /** The mktime function converts the broken-down time, expressed as local time,
147 in the structure pointed to by timeptr into a calendar time value with the
148 same encoding as that of the values returned by the time function. The
149 original values of the tm_wday and tm_yday components of the structure are
150 ignored, and the original values of the other components are not
151 restricted to the ranges indicated above. On successful completion,
152 the values of the tm_wday and tm_yday components of the structure are set
153 appropriately, and the other components are set to represent the specified
154 calendar time, but with their values forced to the ranges indicated above;
155 the final value of tm_mday is not set until tm_mon and tm_year
156 are determined.
157
158 @return The mktime function returns the specified calendar time encoded
159 as a value of type time_t. If the calendar time cannot be
160 represented, the function returns the value (time_t)(-1).
161 **/
162 time_t mktime(struct tm *timeptr);
163
164 /** The time function determines the current calendar time.
165
166 The encoding of the value is unspecified.
167
168 @return The time function returns the implementation's best approximation
169 of the current calendar time. The value (time_t)(-1) is returned
170 if the calendar time is not available. If timer is not a null
171 pointer, the return value is also assigned to the object it
172 points to.
173 **/
174 time_t time(time_t *timer);
175
176 /* ################# Time Conversion Functions ########################## */
177
178 /** The asctime function converts the broken-down time in the structure pointed
179 to by timeptr into a string in the form
180 Sun Sep 16 01:03:52 1973\n\0
181
182 @return The asctime function returns a pointer to the string.
183 **/
184 char * asctime(const struct tm *timeptr);
185
186 /** The ctime function converts the calendar time pointed to by timer to local
187 time in the form of a string. It is equivalent to asctime(localtime(timer))
188
189 @return The ctime function returns the pointer returned by the asctime
190 function with that broken-down time as argument.
191 **/
192 char * ctime(const time_t *timer);
193
194 /** The gmtime function converts the calendar time pointed to by timer into a
195 brokendown time, expressed as UTC.
196
197 @return The gmtime function returns a pointer to the broken-down time,
198 or a null pointer if the specified time cannot be converted to UTC.
199 **/
200 struct tm * gmtime(const time_t *timer);
201
202 /** The timegm function is the opposite of gmtime.
203
204 @return The calendar time expressed as UTC.
205 **/
206 time_t timegm(struct tm*);
207
208 /** The localtime function converts the calendar time pointed to by timer into
209 a broken-down time, expressed as local time.
210
211 @return The localtime function returns a pointer to the broken-down time,
212 or a null pointer if the specified time cannot be converted to
213 local time.
214 **/
215 struct tm * localtime(const time_t *timer);
216
217 /** The strftime function places characters into the array pointed to by s as
218 controlled by the string pointed to by format. The format shall be a
219 multibyte character sequence, beginning and ending in its initial shift
220 state. The format string consists of zero or more conversion specifiers
221 and ordinary multibyte characters. A conversion specifier consists of
222 a % character, possibly followed by an E or O modifier character
223 (described below), followed by a character that determines the behavior of
224 the conversion specifier.
225
226 All ordinary multibyte characters (including the terminating null
227 character) are copied unchanged into the array. If copying takes place
228 between objects that overlap, the behavior is undefined. No more than
229 maxsize characters are placed into the array. 3 Each conversion specifier
230 is replaced by appropriate characters as described in the following list.
231 The appropriate characters are determined using the LC_TIME category of
232 the current locale and by the values of zero or more members of the
233 broken-down time structure pointed to by timeptr, as specified in brackets
234 in the description. If any of the specified values is outside the normal
235 range, the characters stored are unspecified.
236
237 %a is replaced by the locale's abbreviated weekday name. [tm_wday]
238 %A is replaced by the locale's full weekday name. [tm_wday]
239 %b is replaced by the locale's abbreviated month name. [tm_mon]
240 %B is replaced by the locale's full month name. [tm_mon]
241 %c is replaced by the locale's appropriate date and time representation.
242 %C is replaced by the year divided by 100 and truncated to an integer,
243 as a decimal number (00-99). [tm_year]
244 %d is replaced by the day of the month as a decimal number (01-31). [tm_mday]
245 %D is equivalent to "%m/%d/%y". [tm_mon, tm_mday, tm_year]
246 %e is replaced by the day of the month as a decimal number (1-31);
247 a single digit is preceded by a space. [tm_mday]
248 %F is equivalent to "%Y-%m-%d" (the ISO 8601 date format).
249 [tm_year, tm_mon, tm_mday]
250 %g is replaced by the last 2 digits of the week-based year (see below) as
251 a decimal number (00-99). [tm_year, tm_wday, tm_yday]
252 %G is replaced by the week-based year (see below) as a decimal number
253 (e.g., 1997). [tm_year, tm_wday, tm_yday]
254 %h is equivalent to "%b". [tm_mon]
255 %H is replaced by the hour (24-hour clock) as a decimal number (00-23). [tm_hour]
256 %I is replaced by the hour (12-hour clock) as a decimal number (01-12). [tm_hour]
257 %j is replaced by the day of the year as a decimal number (001-366). [tm_yday]
258 %m is replaced by the month as a decimal number (01-12). [tm_mon]
259 %M is replaced by the minute as a decimal number (00-59). [tm_min]
260 %n is replaced by a new-line character.
261 %p is replaced by the locale's equivalent of the AM/PM designations
262 associated with a 12-hour clock. [tm_hour]
263 %r is replaced by the locale's 12-hour clock time. [tm_hour, tm_min, tm_sec]
264 %R is equivalent to "%H:%M". [tm_hour, tm_min]
265 %S is replaced by the second as a decimal number (00-60). [tm_sec]
266 %t is replaced by a horizontal-tab character.
267 %T is equivalent to "%H:%M:%S" (the ISO 8601 time format).
268 [tm_hour, tm_min, tm_sec]
269 %u is replaced by the ISO 8601 weekday as a decimal number (1-7),
270 where Monday is 1. [tm_wday]
271 %U is replaced by the week number of the year (the first Sunday as the
272 first day of week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
273 %V is replaced by the ISO 8601 week number (see below) as a decimal number
274 (01-53). [tm_year, tm_wday, tm_yday]
275 %w is replaced by the weekday as a decimal number (0-6), where Sunday is 0.
276 [tm_wday]
277 %W is replaced by the week number of the year (the first Monday as the
278 first day of week 1) as a decimal number (00-53). [tm_year, tm_wday, tm_yday]
279 %x is replaced by the locale's appropriate date representation.
280 %X is replaced by the locale's appropriate time representation.
281 %y is replaced by the last 2 digits of the year as a decimal
282 number (00-99). [tm_year]
283 %Y is replaced by the year as a decimal number (e.g., 1997). [tm_year]
284 %z is replaced by the offset from UTC in the ISO 8601 format "-0430"
285 (meaning 4 hours 30 minutes behind UTC, west of Greenwich), or by no
286 characters if no time zone is determinable. [tm_isdst]
287 %Z is replaced by the locale's time zone name or abbreviation, or by no
288 characters if no time zone is determinable. [tm_isdst]
289 %% is replaced by %.
290
291 Some conversion specifiers can be modified by the inclusion of an E or O
292 modifier character to indicate an alternative format or specification.
293 If the alternative format or specification does not exist for the current
294 locale, the modifier is ignored. %Ec is replaced by the locale's
295 alternative date and time representation.
296
297 %EC is replaced by the name of the base year (period) in the locale's
298 alternative representation.
299 %Ex is replaced by the locale's alternative date representation.
300 %EX is replaced by the locale's alternative time representation.
301 %Ey is replaced by the offset from %EC (year only) in the locale's
302 alternative representation.
303 %EY is replaced by the locale's full alternative year representation.
304 %Od is replaced by the day of the month, using the locale's alternative
305 numeric symbols (filled as needed with leading zeros, or with leading
306 spaces if there is no alternative symbol for zero).
307 %Oe is replaced by the day of the month, using the locale's alternative
308 numeric symbols (filled as needed with leading spaces).
309 %OH is replaced by the hour (24-hour clock), using the locale's
310 alternative numeric symbols.
311 %OI is replaced by the hour (12-hour clock), using the locale's
312 alternative numeric symbols.
313 %Om is replaced by the month, using the locale's alternative numeric symbols.
314 %OM is replaced by the minutes, using the locale's alternative numeric symbols.
315 %OS is replaced by the seconds, using the locale's alternative numeric symbols.
316 %Ou is replaced by the ISO 8601 weekday as a number in the locale's
317 alternative representation, where Monday is 1.
318 %OU is replaced by the week number, using the locale's alternative numeric symbols.
319 %OV is replaced by the ISO 8601 week number, using the locale's alternative
320 numeric symbols.
321 %Ow is replaced by the weekday as a number, using the locale's alternative
322 numeric symbols.
323 %OW is replaced by the week number of the year, using the locale's
324 alternative numeric symbols.
325 %Oy is replaced by the last 2 digits of the year, using the locale's
326 alternative numeric symbols.
327
328 %g, %G, and %V give values according to the ISO 8601 week-based year. In
329 this system, weeks begin on a Monday and week 1 of the year is the week
330 that includes January 4th, which is also the week that includes the first
331 Thursday of the year, and is also the first week that contains at least
332 four days in the year. If the first Monday of January is the 2nd, 3rd, or
333 4th, the preceding days are part of the last week of the preceding year;
334 thus, for Saturday 2nd January 1999, %G is replaced by 1998 and %V is
335 replaced by 53. If December 29th, 30th, or 31st is a Monday, it and any
336 following days are part of week 1 of the following year. Thus, for Tuesday
337 30th December 1997, %G is replaced by 1998 and %V is replaced by 01.
338
339 If a conversion specifier is not one of the above, the behavior is undefined.
340
341 In the "C" locale, the E and O modifiers are ignored and the replacement
342 strings for the following specifiers are:
343 %a the first three characters of %A.
344 %A one of "Sunday", "Monday", ... , "Saturday".
345 %b the first three characters of %B.
346 %B one of "January", "February", ... , "December".
347 %c equivalent to "%a %b %e %T %Y".
348 %p one of "AM" or "PM".
349 %r equivalent to "%I:%M:%S %p".
350 %x equivalent to "%m/%d/%y".
351 %X equivalent to %T.
352 %Z implementation-defined.
353
354 @param s Pointer to the buffer in which to store the result.
355 @param maxsize Maximum number of characters to put into buffer s.
356 @param format Format string, as described above.
357 @param timeptr Pointer to a broken-down time structure containing the
358 time to format.
359
360 @return If the total number of resulting characters including the
361 terminating null character is not more than maxsize, the
362 strftime function returns the number of characters placed into
363 the array pointed to by s not including the terminating null
364 character. Otherwise, zero is returned and the contents of the
365 array are indeterminate.
366 **/
367 size_t strftime( char * __restrict s, size_t maxsize,
368 const char * __restrict format,
369 const struct tm * __restrict timeptr);
370
371 char *strptime(const char *, const char * format, struct tm*);
372
373
374 /* ################# Implementation Functions ########################### */
375
376 clock_t __getCPS(void);
377
378 #endif /* _TIME_H */