Boost logo

Boost :

Subject: Re: [boost] [datetime] IANA Time Zone Database
From: Jeff Garland (azswdude_at_[hidden])
Date: 2012-11-09 06:29:28

On Fri, Nov 9, 2012 at 3:22 AM, Maxim Yegorushkin <
maxim.yegorushkin_at_[hidden]> wrote:

> Thinking more about it, my local times are coming in as broken down time
> representation (year, month, ...), so I won't be dealing with streams at
> all.
> Is there a way to do timezone conversions without using streams? Something
> similar to pytz:
> timezone paris("Europe/Paris"), utc("UTC");
> date_time t(2012, 10, 9, 10, 19, 0); // no timezone associated
> date_time utc_t(paris.localize(t).**astimezone(utc));
> ?
You're probably asking about locale, but this you can do in date_time:

 ptime pt(date(2004,Nov,5), hours(10));
 time_zone_ptr zone(new posix_time_zone("MST-07"));
 local_date_time az(pt, zone);
 cout << az.utc_time() << endl; // 10am 2004-Nov-5
 cout << az.local_time() << endl; // 3am 2004-Nov-5
 time_zone_ptr nyc_zone = ... //get an nyc timezone
 local_date_time nyc = az.local_time_in(nyc_zone);

In bdt the time_zone is abstract -- so you can build your own time
zone names and such in any fashion you like. What's needed to handle
all the historic cases correctly is a derivative of time_zone which has
the history and when asked to convert local to utc, adjusts
appropriately for the
relative time historically (effectively a list of offset rules).
There's an example and
code that creates custom timezone types. And lastly, you'd need to create some
code to parse the iana data and create the tz objects to lookup by
string...not a
huge amount of work. Certainly this should be out of the box
some day...

Boost list run by bdawes at, gregod at, cpdaniel at, john at