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