4 #define TM_YEAR_BASE 1900
6 /*******************************************************************
7 yield the difference between *A and *B, in seconds, ignoring leap seconds
8 ********************************************************************/
9 static int tm_diff(struct tm *a, struct tm *b)
11 int ay = a->tm_year + (TM_YEAR_BASE - 1);
12 int by = b->tm_year + (TM_YEAR_BASE - 1);
13 int intervening_leap_days =
14 (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
16 int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
17 int hours = 24*days + (a->tm_hour - b->tm_hour);
18 int minutes = 60*hours + (a->tm_min - b->tm_min);
19 int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
24 /*******************************************************************
25 return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
26 ******************************************************************/
27 static int TimeZone(time_t t)
29 struct tm *tm = gmtime(&t);
37 return tm_diff(&tm_utc,tm);
40 time_t timegm2(struct tm *tm)
50 tm2.tm_isdst = tm3.tm_isdst;
64 for (t=tnow; t < tnow + (400 * 24 * 60 * 60); t += 600) {
67 if (timegm2(&tm) != timegm(&tm)) {
68 printf("diff=%d at %s",
69 timegm2(&tm) - timegm(&tm),