[comp.sys.sun] Timezones anyone?

mark@uunet.uu.net (04/07/90)

I have need of code that takes a partially filled in time structure, and
from the information listed below, determines if that time falls within a
period that is in daylight savings time.

The time structure looks like this:

struct tm {
	int tm_sec = 0;
	int tm_min = 0;
	int tm_hour = 23;
	int tm_mday = 1;
	int tm_mon = 0;
	int tm_year = 90;
	int tm_wday;           /* Doesn't matter */
	int tm_yday;           /* ditto */
	int tm_isdst;          /* This is what I want to fill in */
	char *tm_zone;	       /* set from a prior call to localtime() */
	long tm_gmtoff;        /* set by same call to localtime() */
}

I have a function that will take a time structure and return the long
integer representation of that time structure (the reverse of
localtime()), but it requires the tm_isdst to be set.  I need a way of
determining from the month, day, year, hour, and minute whether it is or
is not daylight savings time.

As a kludge work-around I am calculating the long with whatever the flag
is set to at the current time.  This at least gets me in the ballpark.  I
then take that long int and run it back through localtime() to determine
the proper setting of tm_isdst, which is then set into the first time
structure and the long int calculation is repeated.  UUUUUGGGGLLLYYYY!
And it breaks anytime the target time happens to be in the hour lost or
gained at the exact time the changeover to/from daylight savings time is
made.  I don't like it, but it's the best I can do from what I have been
able to find.

I am sorry about the length of this posting, but I want to give my
potential assistants all the information they need.  Can anyone help
me?????

Mark Galbraith                                     Voice: +1 415 449 6881
Programmer/Analyst                                UUCP: uunet!deltam!mark
System Administrator/Postmaster                   Domain: mark@deltam.com
Delta Microsystems, Inc.                           Compuserve: 76234,3126

guy@uunet.uu.net (Guy Harris) (04/10/90)

>I have a function that will take a time structure and return the long
>integer representation of that time structure (the reverse of
>localtime()), but it requires the tm_isdst to be set.

So does SunOS 4.x (the "struct tm" you gave included "tm_zone" and
"tm_isgmtoff", so you have 4.x), and theirs *doesn't* require "tm_isdst"
to be set - it leaves "tm_isdst" set to the correct value.  See the
description of "timelocal()" in CTIME(3).  (This routine comes with the
Arthur Olson time zone code distribution - that's whence the SunOS version
came - so other systems may have it as well.)

SunOS 4.1 will have the ANSI C "mktime()" routine, which is similar except
that you'd have to set "tm_isdst" to -1 to have it figure out whether the
time was in DST or not.  (That routine comes with the most recent version
of the Olson time zone code distribution, and since it's in the ANSI C
spec most systems will eventually have it.)