Boost logo

Boost Users :

From: Brendon Costa (bcosta_at_[hidden])
Date: 2005-08-21 20:46:34

Thanks for the reply. See below for notes...

>Hi Brendan -
>All of the 'clock' calls depend on the operating system time zone setup to
>perform the utc/local conversion. So I suspect something about your system
>setup is requiring you to call tzset() to initialize the environment for
>localtime() and gmtime() to work correctly. Not sure why that would be. I
>presume after tmset() is called once it never needs to be called again?
Yes it only needs to be called once per process. tzset() will initialize
the systems time zone information for use in calls to localtime_r. It
needs to be called once for the process before making a call to
localtime or a few other functions that implicitly depend upon the
timezone information.

Here is an excerpt from the localtime man page that is relevant:

The gmtime_r() and localtime_r() functions provide the same
functionality as gmtime() and localtime() differing in that the caller
must supply a buffer area result in which the result is stored; also,
localtime_r() does not imply initialization of the local time conversion
information; the application may need to do so by calling tzset(3).

I am not sure if calling tzset() is a patch that should be made to the
boost date time library (Don't know what effects it may have on other
systems) or if it is something that I should request for the NetBSD
maintainers (I assume there is a good reason localtime_r() does not call
tzset() itself, as it is explicitly stated in the NetBSD man pages that
the user may need to do so).

>BTW, in 1.33 there's better support for local time than the old
>c_local_adjustor. You might have a look at the tz database functions that
>allow you to do adjusment via regions:
> tz_database tz_db;
> //data file in lib/date_time/data
> tz_db.load_from_file("date_time_zonespec.csv");
> time_zone_ptr mb_tz = tz_db.time_zone_from_region("Australia/Melbourne");
>The returned timezone has string names for the timezone, utc offsets, and
>daylight savings rules built in.
Is there any way of loading the systems current timezone from the
database? I dont want to have to require the user to specify the
timezone for each application as a part of its configuration, and it
can't be hardcoded as the application can be run in various different
timezones. I had a brief look through the new timezone stuff and couldnt
find anything for doing this (Though sometimes I am quite blind to what
is right in front of me...)

Thanks again for the reply. By the way the date time library is very
useful! Thanks for all the hard work that has been put into it.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at