Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-02-28 21:48:36


On Mon, 28 Feb 2005 18:09:21 -0800, Cory Nelson wrote
> Is there a function in date_time to do UTC to local time conversions?

In 1.32 there are some primative tools to help your if you know things like
the timezone offset you want to convert from at compile time. See

http://www.boost.org/doc/html/date_time/posix_time.html#date_time.posix_time.local_time_adjust

for more information.

In CVS, and should be ready for 1.33, there is a major new feature for local
times and dynamic timezones. In a nutshell you can convert to local time
using posix tz specifications or using a timezone database. So let's say you
have the local time in sydney austrialia and you want to convert to UTC:

    //construct the tz for sydney au
    boost::shared_ptr<time_zone_base>
      sydney_tz(new posix_time_zone("EST+10EST,M10.5.0,M3.5.0/03:00"));
    date d(2004,Jan,1);
    time_duration td = hours(1) + minutes(15);
    //2004-Jan-1 01:15:00 in sydney
    local_date_time sidney_time(d,td,sydney_tz);
    ptime utc = sidney_time.utc_time();

    //or the other way starting with a UTC time and going to local
    ptime some_utc_time(....);
    local_date_time sydney_time(some_utc_time, sydney_tz);

You can find the new online docs at:
http://www.meta-comm.com/engineering/resources/cs-win32_metacomm/doc/html/date_time/local_time.html
Feedback appreciated.

Only warning is that we haven't worked out all the kinks in I/O and
portability of this new code.

HTH,

Jeff


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