105
102
static void ComputeGMT(PRTime time, PRExplodedTime *gmt);
106
static int IsLeapYear(PRInt16 year);
103
static int IsLeapYear(PRInt16 year);
107
104
static void ApplySecOffset(PRExplodedTime *time, PRInt32 secOffset);
169
165
/* Compute the time of day. */
171
167
gmt->tm_hour = rem / 3600;
173
169
gmt->tm_min = rem / 60;
174
170
gmt->tm_sec = rem % 60;
176
/* Compute the four-year span containing the specified time */
178
tmp = numDays / (4 * 365 + 1);
179
rem = numDays % (4 * 365 + 1);
183
rem += (4 * 365 + 1);
187
* Compute the year after 1900 by taking the four-year span and
188
* adjusting for the remainder. This works because 2000 is a
189
* leap year, and 1900 and 2100 are out of the range.
192
tmp = (tmp * 4) + 1970;
198
* 1972 has 366 days (leap year)
202
if (rem >= 365) { /* 1971, etc. */
205
if (rem >= 365) { /* 1972, etc. */
208
if (rem >= 366) { /* 1973, etc. */
173
* Compute the year by finding the 400 year period, then working
176
* Since numDays is originally the number of days since January 1, 1970,
177
* we must change it to be the number of days from January 1, 0001.
180
numDays += 719162; /* 719162 = days from year 1 up to 1970 */
181
tmp = numDays / 146097; /* 146097 = days in 400 years */
182
rem = numDays % 146097;
183
gmt->tm_year = tmp * 400 + 1;
185
/* Compute the 100 year period. */
187
tmp = rem / 36524; /* 36524 = days in 100 years */
189
if (tmp == 4) { /* the 400th year is a leap year */
193
gmt->tm_year += tmp * 100;
195
/* Compute the 4 year period. */
197
tmp = rem / 1461; /* 1461 = days in 4 years */
199
gmt->tm_year += tmp * 4;
201
/* Compute which year in the 4. */
205
if (tmp == 4) { /* the 4th year is a leap year */
218
211
gmt->tm_yday = rem;
212
isLeap = IsLeapYear(gmt->tm_year);
220
214
/* Compute the month and day of month. */
510
500
* returns the time parameters for the local time zone
512
502
* The following uses localtime() from the standard C library.
513
* (time.h) This is our fallback implementation. Unix and PC
514
* use this version. Mac has its own machine-dependent
503
* (time.h) This is our fallback implementation. Unix, PC, and BeOS
504
* use this version. A platform may have its own machine-dependent
515
505
* implementation of this function.
517
507
*-------------------------------------------------------------------------
572
558
* structs returned for timezones west of Greenwich when clock == 0.
576
tmPtr = Maclocaltime(clock);
578
561
tmPtr = localtime(clock);
581
563
#if defined(WIN16) || defined(XP_OS2)
582
564
if ( (PRInt32) *clock < 0 ||