2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 Convert a time into UTC, reentrant.
8 /* At the moment no daylight saving time information
9 * Implementation has to be changed when DST is implemented in AROS
11 static int __dstflag
= -1;
13 static char monthtable
[] =
15 /* JanFebMarAprMayJunJulAugSepOktNov */
16 31,29,31,30,31,30,31,31,30,31,30
19 /*****************************************************************************
24 struct tm
* gmtime_r (
31 The gmtime_r() function converts the calendar time tt to
32 broken-down time representation, expressed in Coordinated Universal
37 tt - The time to convert
38 tm - A struct tm to store the result in
41 The pointer passed in tm, containing the broken down time in
42 Coordinated Universal Time (UTC).
59 time(), ctime_r(), asctime_r(), localtime_r()
64 1. every 4th year is a leap year
66 2. every 100th year is none
70 4. 1900 was none, 2000 is one
72 ******************************************************************************/
81 tm
->tm_sec
= tim
% 60;
84 tm
->tm_min
= tim
% 60;
88 719162 number of days between 1.1.1 and 1.1.1970 if the calendar
89 would go so far which it doesn't :-) this is true for all of the
92 tm
->tm_hour
= tim
% 24;
93 tim
= tim
/ 24 + 719162;
95 tm
->tm_wday
= (tim
+ 1) % 7;
97 /* 146097 number of days from 1.1.1 to 1.1.401 */
98 tm
->tm_year
= tim
/ 146097 * 400 - 1899;
101 /* 145731 number of days from 1.1.1 to 1.1.400 */
104 leapyear
++; /* The day is in one of the 400th */
106 /* Be careful: The last of the 4 centuries is 1 day longer */
114 /* 36524 number of days from 1.1.1 to 1.1.101 */
115 tm
->tm_year
+= tim
/ 36524 * 100;
118 /* 36159 number of days from 1.1.1 to 1.1.100 */
120 leapyear
--; /* The day is in one of the 100th */
122 /* 1461 number of days from 1.1.1 to 1.1.5 */
123 tm
->tm_year
+= tim
/ 1461 * 4;
126 /* 1095 number of days from 1.1.1 to 1.1.4 */
129 leapyear
++; /* The day is in one of the 4th */
131 /* Be careful: The 4th year is 1 day longer */
139 /* 365 days in a normal year */
140 tm
->tm_year
+= tim
/ 365;
141 tim
= tim
% 365 + leapday
;
145 if (!leapyear
&& tim
>= 31+28)
146 tim
++; /* add 1 for 29-Feb if no leap year */
151 if (tim
< monthtable
[i
])
158 tm
->tm_mday
= tim
+ 1;
160 tm
->tm_isdst
= __dstflag
;