ack/lang/cem/libcc.ansi/core/time/localtime.c

36 lines
860 B
C
Raw Normal View History

1989-06-12 15:22:14 +00:00
/*
* localtime - convert a calendar time into broken down time
*/
1994-06-24 14:02:31 +00:00
/* $Id$ */
1989-06-12 15:22:14 +00:00
2018-06-21 20:33:47 +00:00
#include <time.h>
#include "loc_time.h"
1989-06-12 15:22:14 +00:00
/* We must be careful, since an int can't represent all the seconds in a day.
* Hence the adjustment of minutes when adding timezone and dst information.
* This assumes that both must be expressable in multiples of a minute.
* Furthermore, it is assumed that both fit into an integer when expressed as
* minutes (this is about 22 days, so this should not cause any problems).
*/
2018-06-21 20:33:47 +00:00
struct tm*
localtime(const time_t* timer)
1989-06-12 15:22:14 +00:00
{
2018-06-21 20:33:47 +00:00
struct tm* timep;
1989-06-12 15:22:14 +00:00
unsigned dst;
1989-12-18 15:33:48 +00:00
_tzset();
2018-06-21 20:33:47 +00:00
timep = gmtime(timer); /* tm->tm_isdst == 0 */
1989-12-18 15:33:48 +00:00
timep->tm_min -= _timezone / 60;
timep->tm_sec -= _timezone % 60;
1989-06-12 15:22:14 +00:00
mktime(timep);
dst = _dstget(timep);
2018-06-21 20:33:47 +00:00
if (dst)
{
1989-06-12 15:22:14 +00:00
timep->tm_min += dst / 60;
1989-12-18 15:33:48 +00:00
timep->tm_sec += dst % 60;
1989-06-12 15:22:14 +00:00
mktime(timep);
}
return timep;
}