Boost Users :
From: Jeff Garland (jeff_at_[hidden])
Date: 2005-01-11 10:06:34
On Tue, 11 Jan 2005 09:22:06 -0500, Caleb Epstein wrote
> On Tue, 11 Jan 2005 07:26:20 -0600, Bill Lear <rael_at_[hidden]> wrote:
> > I'd like to determine the total number of seconds between a date and
> > the epoch ('00:00:00 1970-01-01 UTC'), The date can be in a timezone
> > that has daylight savings. The date should be converted to UTC, with
> > appropriate daylight savings adjustments made, and then the epoch
> > subtracted from it. This should mirror the unix GNU 'date' utility,
> > which can be run as:
> > % TZ="America/New_York" date --date='2004-10-04 12:14:32' +%s
> > 1096906472
> > I've looked at the doc, but it's not clear how to do this. Could
> > someone give me a few pointers, please?
> I would make use of the standard library facilities timelocal or
> timegm to convert a struct tm to time_t format. The former assumes
> the time is expressed in local time (as specified by the TZ
> environment variable or via tzset) and the latter assumes it is in
> The support for timezone conversions in Boost.DateTime is rudimentary
> at best and does not currently make use of operating system
> facilities like the zoneinfo database.
This is true, but in 1.33 this will be vastly improved.
In fact, the experimental version of this is already in CVS. Have a look at
libs/date_time/test/local_time/testtz_database.cpp. There you will find
testcode for a timezone database feature that will allow you do convert
directly based on a regional timezone specification (there's also a posix
timezone specification class). Bascially you load in the timezone data from a
csv file -- one is provided in the libs/date_time/data/ directory that derives
from the timezone database project.
nyc_test = tz_db.time_zone_from_region("America/New_York");
>From the timezone you can determine the utc offset and dst_offset as well as
the start time for dst in a given year. All of this is integrated with a
local_date_time class that can hold the time as well as the timezone pointer
(see testlocal_time.cpp in the same directory).
All this is preliminary as it doesn't have docs and hasn't been tested on lots
of platforms, but if you have a reasonably modern c++ compiler it should work.
I can't guarantee that the interface won't change before the 1.33
release, but things are pretty stable at this point.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net