🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3784

Re: timezone macro for autoconf?

#3784
From: Russ Allbery
Date: Tue, 18 Apr 2000 00:00
39 lines
2690 bytes
In gnu.utils.help, Paul Eggert <eggert@twinsun.com> writes:
> Russ Allbery <rra@stanford.edu> writes:
>> Dan Kegel <dank@alumni.caltech.edu> writes:

>>> Does anyone have a good autoconf macro for figuring out
>>> how to get at the timezone offset (the extern int) portably?

>> No, but I need to write one for INN as well.

> The most portable way to get the time zone offset is to invoke localtime
> and gmtime on the same time_t value, and then compute the offset
> yourself from the two broken-down times.  This works on any system that
> conforms to either K&R C or to Standard C (either 1989 or 1999).

Right.  This is what INN currently falls back to if struct tm doesn't have
the tm_gmtoff member.

> The 'timezone' variable is less accurate than the portable method, as it
> assumes that the same standard time offset is in effect forever, so it
> mishandles changes to the standard time zone offset (which happened last
> month in Argentina, for example).

Why does it assume that?  I must be missing something.  According to the
Solaris 2.6 man page for the time functions:

     The effects of tzset() are thus to change the values of the external
     variables timezone, altzone, daylight, and tzname.  The ctime(),
     localtime(), mktime(), and strftime() functions will also update
     these external variables as if they had called tzset() at the time
     specified by the time_t or struct tm value that they are converting.

so it seems to me that retrieving the value of timezone if tm_isdst is 0
or altzone if tm_isdst is 1 and daylight is positive, provided it is done
immediately after calling localtime(), would be as accurate as using
tm_gmtoff.  It's unfortunately not MT-Safe, but then localtime() isn't
MT-Safe in general anyway.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>
Technical Details
Message-ID: <ylaeiryr7f.fsf@windlord.stanford.edu>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38FBB4DB.DE12E1C4@alumni.caltech.edu> <ylog78chos.fsf@windlord.stanford.edu> <8di5uf$8p0$1@ruby.twinsun.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10c696,8ce1c34c9f5a1eaa
X-Google-Attributes: gid10c696,public
X-Google-Thread: 109f73,8ce1c34c9f5a1eaa
X-Google-Attributes: gid109f73,public
X-Google-Thread: fc89c,8ce1c34c9f5a1eaa
X-Google-Attributes: gidfc89c,public
From: Russ Allbery <rra@stanford.edu>
Subject: Re: timezone macro for autoconf?
Date: 2000/04/18
Message-ID: <ylaeiryr7f.fsf@windlord.stanford.edu>
X-Deja-AN: 612888733
References: <38FBB4DB.DE12E1C4@alumni.caltech.edu> <ylog78chos.fsf@windlord.stanford.edu> <8di5uf$8p0$1@ruby.twinsun.com>
Content-Type: text/plain; charset=us-ascii
Organization: The Eyrie
Mime-Version: 1.0
User-Agent: Gnus/5.0802 (Gnus v5.8.2) XEmacs/21.1 (Biscayne)
Newsgroups: comp.unix.programmer,comp.os.linux.development.apps,gnu.utils.help