
----- Original Message -----
From: Maxim Yegorushkin <maxim.yegorushkin@gmail.com> To: boost@lists.boost.org Cc: Sent: Friday, November 9, 2012 12:22 PM Subject: Re: [boost] [datetime] IANA Time Zone Database
On 08/11/12 15:15, Artyom Beilis wrote:
You can use Boost.Locale that is compiled with ICU backend.
ICU supports Time Zone database and you can specify the timezone by its name, parse time or create
date_time object and get POSIX (UTC) time form it.
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
________________________________ From: Maxim Yegorushkin <maxim.yegorushkin@gmail.com> To: boost@lists.boost.org Sent: Thursday, November 8, 2012 4:53 PM Subject: [boost] [datetime] IANA Time Zone Database
Hi Boost,
I have files with timestamps in various timezones. I would like to be able to convert these timestamps, no matter what timezone they are in (I know the names of the timezones) to UTC timestamps.
I looked through datatime library documentation and found date_time_zonespec.csv database which doesn't seem to support
On 08/11/12 17:36, Maxim Yegorushkin wrote: the
notion of different rules for the same timezone depending on the date. For example, Russia used to have summer time but not any more. Another method seems to be passing a timezone specification string manually, which requires the user to figure what it should be for a particular date.
In other words, given a timestamp and its timezone, I would like to be able to convert that timestamp into a UTC timestamp using conversion rules in force at that particular date in the past. Ideally, this would use IANA Time Zone Database or something similar. Is there a facility in boost to do just that?
Oh, thanks Artyom.
That is quite a surprising place to find this functionality. Not sure why it is not in datetime library.
Anyway, I managed to get a small test working: [snip]
Thanks a lot!
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));
?
-- Maxim
First you can create boost::locale::calendar using TZ name http://www.boost.org/doc/libs/1_52_0/libs/locale/doc/html/classboost_1_1loca... Than you create a date_time object using calendar and than setup all parameters you need. http://www.boost.org/doc/libs/1_52_0/libs/locale/doc/html/classboost_1_1loca... It should be something like using namespace boost::locale::period; boost::locale::date_time dt( year(2012) + month(10) + day(9) + hour(10) + minute(19) + second(0), boost::locale::calendar("Europe/Paris")); Than you can get a POSIX time from it dt.time(), print it to stream with UTC time zone or create other date_time object like boost::locale::date_time dt_utc(dt.time(),boost::locale::calendar("UTC")); And fetch its parameters. I hadn't tested the chunk of code above but this is a general direction. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/