Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-08-20 12:09:47


On Wed, 17 Aug 2005 12:56:16 +1000, Brendon Costa wrote
> Hi,
>
> I have noticed that there seems to be a problem with the boost
> date_time library 1.33 (Downloaded about 2 days ago) when trying to
> use the localtime information under a NetBSD system. Specifically
> when I have a small test program:
>
> #include "boost/date_time/posix_time/posix_time.hpp"
> #include "boost/date_time/c_local_time_adjustor.hpp"
>
> #include <iostream>
>
> int
> main()
> {
> using namespace boost::posix_time;
>
> ptime loc = microsec_clock::local_time();
> ptime utc = microsec_clock::universal_time();
> std::cout << "Local: " << to_simple_string(loc) <<
> std::endl; std::cout << "UTC: " << to_simple_string(utc)
> << std::endl;
>
> std::cout << "Local again: "
> << to_simple_string(
> boost::date_time::c_local_adjustor<ptime>::utc_to_local(utc)
> ) << std::endl; return 0; }
>
> It will display the same time for both UTC time and Local time
> (Living in Melbourn Australia) where I expected them to differ.

Hi Brendan -

All of the 'clock' calls depend on the operating system time zone setup to
perform the utc/local conversion. So I suspect something about your system
setup is requiring you to call tzset() to initialize the environment for
localtime() and gmtime() to work correctly. Not sure why that would be. I
presume after tmset() is called once it never needs to be called again?

BTW, in 1.33 there's better support for local time than the old
c_local_adjustor. You might have a look at the tz database functions that
allow you to do adjusment via regions:
  
 tz_database tz_db;
 //data file in lib/date_time/data
 tz_db.load_from_file("date_time_zonespec.csv");
 time_zone_ptr mb_tz = tz_db.time_zone_from_region("Australia/Melbourne");
 
The returned timezone has string names for the timezone, utc offsets, and
daylight savings rules built in.

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