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