localtime.c

Go to the documentation of this file.
00001 /*
00002  * localtime - convert a calendar time into broken down time
00003  */
00004 /* $Header: /opt/proj/minix/cvsroot/src/lib/ansi/localtime.c,v 1.1.1.1 2005/04/21 14:56:05 beng Exp $ */
00005 
00006 #include        <time.h>
00007 #include        "loc_time.h"
00008 
00009 /* We must be careful, since an int can't represent all the seconds in a day.
00010  * Hence the adjustment of minutes when adding timezone and dst information.
00011  * This assumes that both must be expressable in multiples of a minute.
00012  * Furthermore, it is assumed that both fit into an integer when expressed as
00013  * minutes (this is about 22 days, so this should not cause any problems). 
00014  */
00015 struct tm *
00016 localtime(const time_t *timer)
00017 {
00018         struct tm *timep;
00019         unsigned dst;
00020 
00021         _tzset();
00022         timep = gmtime(timer);                  /* tm->tm_isdst == 0 */
00023         timep->tm_min -= _timezone / 60;
00024         timep->tm_sec -= _timezone % 60;
00025         mktime(timep);
00026 
00027         dst = _dstget(timep);
00028         if (dst) {
00029                 timep->tm_min += dst / 60;
00030                 timep->tm_sec += dst % 60;
00031                 mktime(timep);
00032         }
00033         return timep;
00034 }

Generated on Fri Apr 14 22:57:25 2006 for minix by  doxygen 1.4.6