Using boost::date_time for timezones
Hello All,
I'm new to Boost and interested in using it for timezone conversions but
I'm not finding it terribly clear. An example, which works fine, uses
something of the form:
typedef boost::date_time::local_adjustor
On Wed, 18 Aug 2004 20:33:10 +0100, Duncan Woods wrote
Hello All,
I'm new to Boost and interested in using it for timezone conversions but I'm not finding it terribly clear. An example, which works fine, uses something of the form:
typedef boost::date_time::local_adjustor
us_eastern;
Yes, this allows you to build static converters for a small number of time zones with well defined rules. If there isn't a rule set in the library that suits your application you would need to create one of your own. Since this is totally undocumented, I'll help you if you really want to go this way.
1. My problem is that I wish to use DST settings other than US and found definitions such as eu_dst_trait in local_timezone_defs.hpp but these seem unused and unusable. Would it require implementation of dst_rules.hpp type classes? If so, Boost would not give much advantage.
I agree date_time doesn't support local time adjustments well...yet.
2. I would also have liked to specify dst & timezone combinations at run-time which dynamic_local_time_adjustor sounds like it might do - but it appears to have no members.
It has members. Look at the bottom of libs/date_time/test/posix_time/testlocal_adjustor.cpp. Note the comment: //still experimental
3. Will date_time use the 'tz database' in the future?
The short answer is yes and I expect it before 1.33.
The long answer is that in future releases there will be a generic time_zone
class that encapsulates the glob of interfaces that the library needs to
correctly handle a time zone. The abstraction will use subclassing to support
different concrete time zone implementations. We have a working prototype now
that uses Posix timezone strings to construct. So you can do something like:
posix_time_zone arizona_tz("MST-07");
posix_time_zone ny_tz("EST-05EDT,M4.1.0,M10.5.0");
We are working on a variant that will use data from the TZ database so you can
say something like
boost::shared_ptr
Jeff, Thanks for your reply. I'm afraid I will have to find another solution short-term but look forward to helping try out some of the betas in the future. C++ has been aching for a definitive date-time library - what are the current leaders? re: tz database, it would be helpful to support caching the db results in memory to avoid accidental/lazy implementations going to disk each time. Thanks, Duncan Jeff Garland wrote:
On Wed, 18 Aug 2004 20:33:10 +0100, Duncan Woods wrote
Hello All,
I'm new to Boost and interested in using it for timezone conversions but I'm not finding it terribly clear. An example, which works fine, uses something of the form:
typedef boost::date_time::local_adjustor
us_eastern; Yes, this allows you to build static converters for a small number of time zones with well defined rules. If there isn't a rule set in the library that suits your application you would need to create one of your own. Since this is totally undocumented, I'll help you if you really want to go this way.
1. My problem is that I wish to use DST settings other than US and found definitions such as eu_dst_trait in local_timezone_defs.hpp but these seem unused and unusable. Would it require implementation of dst_rules.hpp type classes? If so, Boost would not give much advantage.
I agree date_time doesn't support local time adjustments well...yet.
2. I would also have liked to specify dst & timezone combinations at run-time which dynamic_local_time_adjustor sounds like it might do - but it appears to have no members.
It has members. Look at the bottom of libs/date_time/test/posix_time/testlocal_adjustor.cpp. Note the comment: //still experimental
3. Will date_time use the 'tz database' in the future?
The short answer is yes and I expect it before 1.33.
The long answer is that in future releases there will be a generic time_zone class that encapsulates the glob of interfaces that the library needs to correctly handle a time zone. The abstraction will use subclassing to support different concrete time zone implementations. We have a working prototype now that uses Posix timezone strings to construct. So you can do something like:
posix_time_zone arizona_tz("MST-07"); posix_time_zone ny_tz("EST-05EDT,M4.1.0,M10.5.0");
We are working on a variant that will use data from the TZ database so you can say something like boost::shared_ptr
tz(tz_database.find("America/New York")); What we are NOT planning to do is supporting all the historic timezones of the timezone database -- doesn't seem like it's worth the complication. We also are not planning on reading the TZ database binary format directly (it's a directory with binary files for each timezone for those that don't know). Rather we are looking at condensing the contents (probably fron VCALENDAR form) down to a single csv file that can be read in by the application and can be modified as need be using text editors, excel, etc. So in your app it would look something like: tz_database db("zones.csv"); boost::shared_ptr
tz(db.find("America/New York")); Of course this comes with a new local_time class that can use time zones natively to adjust, do calculations, input/output, etc. So in particular, I expect to be able to write the following kind of code tz_database db("zones.csv"); boost::shared_ptr
tz(db.find("America/New York")); local_date_time ny_time = second_clock::local_time(tz); //2004-Aug-18 05:27:00 EDT std::cout << "The current time in New York is: " << ny_time << std::endl; HTH,
Jeff
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Thu, 19 Aug 2004 10:06:57 +0100, Duncan Woods wrote
Jeff,
Thanks for your reply. I'm afraid I will have to find another solution short-term but look forward to helping try out some of the
Sorry to hear that.
betas in the future. C++ has been aching for a definitive date-time library - what are the current leaders?
Good question, but you know my answer would be biased ;-) As for local time support, I don't really know of any libraries that do it really well. IBM has some timezone support as do the Roque Wave libraries. Still I don't think either use the TZ database or th Posix tz naming. Bottom line here is I'm hoping to raise the bar...
re: tz database, it would be helpful to support caching the db results in memory to avoid accidental/lazy implementations going to disk each time.
Yes, the plan is to read in from the csv file into memory. User will control the lifetime of the object. For the whole world this will amount to a few hundred entries in a map. And of course you can edit down the csv file to suit your needs. Jeff
Jeff, It sounds good - best of luck. I shall keep my on eye on future releases. I hadn't heard of roque wave (costs money though) and never thought to check IBM. For anyone interested, having beaten my head against many different walls and become the trivia king of world-wide DST rules, my quick win32 solution was: 1. Preload the SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones registry branch into a map 2. Use the win32 SystemTimeToTzSpecificLocalTime for applying a time-zone to UTC 3. Use the WINE implementation of TzSpecificLocalTimeToSystemTime for returning to UTC since for win32 it is XP and win2003 Server only. 4. Enable\Disable dst conversion by changing the TIME_ZONE_INFORMATION::DaylightDate.wMonth to zero Satisfies a shed load of typical rules but - wow - its horrid! Thanks, Duncan Jeff Garland wrote:
On Thu, 19 Aug 2004 10:06:57 +0100, Duncan Woods wrote
Jeff,
Thanks for your reply. I'm afraid I will have to find another solution short-term but look forward to helping try out some of the
Sorry to hear that.
betas in the future. C++ has been aching for a definitive date-time library - what are the current leaders?
Good question, but you know my answer would be biased ;-) As for local time support, I don't really know of any libraries that do it really well. IBM has some timezone support as do the Roque Wave libraries. Still I don't think either use the TZ database or th Posix tz naming. Bottom line here is I'm hoping to raise the bar...
re: tz database, it would be helpful to support caching the db results in memory to avoid accidental/lazy implementations going to disk each time.
Yes, the plan is to read in from the csv file into memory. User will control the lifetime of the object. For the whole world this will amount to a few hundred entries in a map. And of course you can edit down the csv file to suit your needs.
Jeff _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Duncan Woods
-
Jeff Garland