Rev | Line | |
---|
[9] | 1 | /*
|
---|
| 2 | * localtime - convert a calendar time into broken down time
|
---|
| 3 | */
|
---|
| 4 | /* $Header: /cvsup/minix/src/lib/ansi/localtime.c,v 1.1.1.1 2005/04/21 14:56:05 beng Exp $ */
|
---|
| 5 |
|
---|
| 6 | #include <time.h>
|
---|
| 7 | #include "loc_time.h"
|
---|
| 8 |
|
---|
| 9 | /* We must be careful, since an int can't represent all the seconds in a day.
|
---|
| 10 | * Hence the adjustment of minutes when adding timezone and dst information.
|
---|
| 11 | * This assumes that both must be expressable in multiples of a minute.
|
---|
| 12 | * Furthermore, it is assumed that both fit into an integer when expressed as
|
---|
| 13 | * minutes (this is about 22 days, so this should not cause any problems).
|
---|
| 14 | */
|
---|
| 15 | struct tm *
|
---|
| 16 | localtime(const time_t *timer)
|
---|
| 17 | {
|
---|
| 18 | struct tm *timep;
|
---|
| 19 | unsigned dst;
|
---|
| 20 |
|
---|
| 21 | _tzset();
|
---|
| 22 | timep = gmtime(timer); /* tm->tm_isdst == 0 */
|
---|
| 23 | timep->tm_min -= _timezone / 60;
|
---|
| 24 | timep->tm_sec -= _timezone % 60;
|
---|
| 25 | mktime(timep);
|
---|
| 26 |
|
---|
| 27 | dst = _dstget(timep);
|
---|
| 28 | if (dst) {
|
---|
| 29 | timep->tm_min += dst / 60;
|
---|
| 30 | timep->tm_sec += dst % 60;
|
---|
| 31 | mktime(timep);
|
---|
| 32 | }
|
---|
| 33 | return timep;
|
---|
| 34 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.