2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 Convert a time into UTC.
8 /* At the moment no daylight saving time information
9 * Implementation has to be changed when DST is implemented in AROS
13 static char monthtable
[] =
15 /* JanFebMarAprMayJunJulAugSepOktNov */
16 31,29,31,30,31,30,31,31,30,31,30
19 /*****************************************************************************
30 The gmtime() function converts the calendar time tt to
31 broken-down time representation, expressed in Coordinated Universal
36 tt - The time to convert
39 The broken down time in Coordinated Universal Time (UTC).
42 This function must not be used in a shared library or
43 in a threaded application.
58 time(), ctime(), asctime(), localtime()
63 1. every 4th year is a leap year
65 2. every 100th year is none
69 4. 1900 was none, 2000 is one
71 ******************************************************************************/
73 static struct tm utim
;
81 utim
.tm_sec
= tim
% 60;
84 utim
.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 utim
.tm_hour
= tim
% 24;
93 tim
= tim
/ 24 + 719162;
95 utim
.tm_wday
= (tim
+ 1) % 7;
97 /* 146097 number of days from 1.1.1 to 1.1.401 */
98 utim
.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 utim
.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 utim
.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 utim
.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 utim
.tm_mday
= tim
+ 1;
160 utim
.tm_isdst
= __dstflag
;