🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #3783

Re: timezone macro for autoconf?

#3783
From: Paul Eggert
Date: Tue, 18 Apr 2000 00:00
35 lines
2403 bytes
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).  For a
code example, please see how glibc strftime.c implements %z in the case
where HAVE_TM_GMTOFF is zero, looking particularly at the tm_diff
function.

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).

The portable method is a bit slow, unfortunately.  If you want extra
speed on systems that support a tm_gmtoff member of struct tm, then I
suggest looking at how, say, GNU fileutils defines HAVE_TM_GMTOFF.
However I should mention that the method for doing this will change in
the next autoconf release, where you'll be able to say something like this:

AC_CHECK_MEMBER(struct tm.tm_gmtoff,
  [AC_DEFINE(HAVE_TM_GMTOFF, 1,
     [Define if struct tm has the tm_gmtoff member.])],
     ,
     [#include <time.h>])

(I suspect that is more than you wanted to know about time zone offsets. :-)
Technical Details
Message-ID: <8di5uf$8p0$1@ruby.twinsun.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38FBB4DB.DE12E1C4@alumni.caltech.edu> <ylog78chos.fsf@windlord.stanford.edu>

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: eggert@twinsun.com (Paul Eggert)
Subject: Re: timezone macro for autoconf?
Date: 2000/04/18
Message-ID: <8di5uf$8p0$1@ruby.twinsun.com>
X-Deja-AN: 612786760
References: <38FBB4DB.DE12E1C4@alumni.caltech.edu> <ylog78chos.fsf@windlord.stanford.edu>
X-Complaints-To: news@twinsun.com
X-Trace: tattoo.twinsun.com 956078862 14132 192.54.239.31 (18 Apr 2000 17:27:42 GMT)
Organization: Twin Sun Inc, El Segundo, CA, USA
NNTP-Posting-Date: 18 Apr 2000 17:27:42 GMT
Newsgroups: comp.unix.programmer,comp.os.linux.development.apps,gnu.utils.help