1 /* $Id: gettime.c 4135 2000-10-19 16:38:13Z kondou $
3 ** Find and return time information portably.
12 #ifdef TIME_WITH_SYS_TIME
13 # include <sys/time.h>
16 # ifdef HAVE_SYS_TIME_H
17 # include <sys/time.h>
25 GetTimeInfo(TIMEINFO *Now)
27 static time_t NextHour;
28 static long LastTzone;
30 int secondsUntilNextHour;
34 #ifndef HAVE_TM_GMTOFF
39 /* Get the basic time. */
40 if (gettimeofday(&tv, (struct timezone *) 0) == -1)
42 Now->time = tv.tv_sec;
43 Now->usec = tv.tv_usec;
45 /* Now get the timezone if the last time < HH:00:00 <= now for some HH. */
46 if (NextHour <= Now->time) {
47 tm = localtime(&Now->time);
50 secondsUntilNextHour = 60 * (60 - tm->tm_min) - tm->tm_sec;
53 LastTzone = (0 - tm->tm_gmtoff) / 60;
55 /* To get the timezone, compare localtime with GMT. */
57 if ((tm = gmtime(&Now->time)) == NULL)
61 /* Assume we are never more than 24 hours away. */
62 LastTzone = gmt.tm_yday - local.tm_yday;
65 else if (LastTzone < -1)
70 /* Scale in the hours and minutes; ignore seconds. */
71 LastTzone += gmt.tm_hour - local.tm_hour;
73 LastTzone += gmt.tm_min - local.tm_min;
74 #endif /* defined(HAVE_TM_GMTOFF) */
76 NextHour = Now->time + secondsUntilNextHour;
78 Now->tzone = LastTzone;