diff --git a/libsrc/common/gmtime.c b/libsrc/common/gmtime.c index 1a2536c5f..85e9de3d0 100644 --- a/libsrc/common/gmtime.c +++ b/libsrc/common/gmtime.c @@ -45,19 +45,29 @@ struct tm* __fastcall__ gmtime (const time_t* timep) { + static struct tm timebuf; time_t t; - /* Check for a valid time spec */ - if (timep == 0) { + /* Check the argument */ + if (timep == 0 || (long) (t = *timep) < 0) { + /* Invalid arg */ return 0; } - /* Get the time and correct for the time zone offset */ - t = *timep + _tz.timezone; + /* Since our ints are just 16 bits, split the given time into seconds, + ** hours and days. Each of the values will fit in a 16 bit variable. + ** The mktime routine will then do the rest. + */ + timebuf.tm_sec = t % 3600; + timebuf.tm_min = 0; + timebuf.tm_hour = (t / 3600) % 24; + timebuf.tm_mday = (t / (3600UL * 24UL)) + 1; + timebuf.tm_mon = 0; + timebuf.tm_year = 70; /* Base value is 1/1/1970 */ - /* Use localtime for conversion */ - return localtime (&t); + /* Call mktime to do the final conversion */ + mktime (&timebuf); + + /* Return the result */ + return &timebuf; } - - - diff --git a/libsrc/common/localtime.c b/libsrc/common/localtime.c index cc6298f8c..48931ea62 100644 --- a/libsrc/common/localtime.c +++ b/libsrc/common/localtime.c @@ -45,31 +45,16 @@ struct tm* __fastcall__ localtime (const time_t* timep) { - static struct tm timebuf; time_t t; - /* Check the argument */ - if (timep == 0 || (long) (t = *timep) < 0) { - /* Invalid arg */ + /* Check for a valid time spec */ + if (timep == 0) { return 0; } - /* Since our ints are just 16 bits, split the given time into seconds, - ** hours and days. Each of the values will fit in a 16 bit variable. - ** The mktime routine will then do the rest. - */ - timebuf.tm_sec = t % 3600; - timebuf.tm_min = 0; - timebuf.tm_hour = (t / 3600) % 24; - timebuf.tm_mday = (t / (3600UL * 24UL)) + 1; - timebuf.tm_mon = 0; - timebuf.tm_year = 70; /* Base value is 1/1/1970 */ + /* Get the time and correct for the time zone offset */ + t = *timep + _tz.timezone; - /* Call mktime to do the final conversion */ - mktime (&timebuf); - - /* Return the result */ - return &timebuf; + /* Use gmtime for conversion */ + return gmtime (&t); } - - diff --git a/libsrc/common/mktime.c b/libsrc/common/mktime.c index 423727751..275589dbb 100644 --- a/libsrc/common/mktime.c +++ b/libsrc/common/mktime.c @@ -180,7 +180,8 @@ time_t __fastcall__ mktime (register struct tm* TM) return DayCount * 86400UL + ((unsigned) TM->tm_hour) * 3600UL + ((unsigned) TM->tm_min) * 60U + - ((unsigned) TM->tm_sec); + ((unsigned) TM->tm_sec) - + _tz.timezone; Error: /* Error exit */