5 #define TM_YEAR_BASE 1900
7 /*******************************************************************
8 yield the difference between *A and *B, in seconds, ignoring leap seconds
9 ********************************************************************/
10 static int tm_diff(struct tm *a, struct tm *b)
12 int ay = a->tm_year + (TM_YEAR_BASE - 1);
13 int by = b->tm_year + (TM_YEAR_BASE - 1);
14 int intervening_leap_days =
15 (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
17 int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
18 int hours = 24*days + (a->tm_hour - b->tm_hour);
19 int minutes = 60*hours + (a->tm_min - b->tm_min);
20 int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
22 printf("tm_diff ay=%d by=%d ild=%d y=%d d=%d h=%d m=%d s=%d am=%d bm=%d asec=%d bsec=%d\n",
23 ay, by, intervening_leap_days, years, days, hours, minutes, seconds,
28 if (a->tm_sec != b->tm_sec)
29 printf("Your timezone file is broken\n");
33 /*******************************************************************
34 return the UTC offset in seconds west of UTC
35 ******************************************************************/
36 static int TimeZone(time_t t)
38 struct tm tm_utc = *(gmtime(&t));
39 return tm_diff(&tm_utc,localtime(&t));
42 int main(int argc, char *argv[])