Boost logo

Boost :

From: Bart (bartmann.nsd_at_[hidden])
Date: 2005-06-13 20:18:58


> Submitted By: Nobody/Anonymous (nobody)
> Assigned to: Jeff Garland (az_sw_dude)
> Summary: local_adjustor::utc_to_local throws "Time label invalid"
>
> Initial Comment:
> using namespace boost::posix_time;
> using namespace boost::date_time;
> using namespace boost::gregorian;
>
> ptime datetime( date( 2005, 4, 2 ), time_duration( 23, 0, 0
> ) );
> typedef local_adjustor< ptime, 3, us_dst > adj;
> ptime adj_time( adj::utc_to_local( datetime ) ); // Fails
> with "Time label invalid"
>
> Compiled on boost 1.32.0 with msvc++ 7.1.3088
>

This is correct.

Since the date and UTC offset you gave would end up right on the transition
into dst, it is considered an invalid time label.

I believe we are going to depricate this code (local_adjustor). With version
1.33 we've introduced a local_date_time. Here's an example showing how to
accomplish the above calculation:

#include <iostream>
#include <boost/date_time/local_time/local_time.hpp>

int main() {
  using namespace boost::gregorian;
  using namespace boost::posix_time;
  using namespace boost::local_time;

  ptime datetime_1(date(2005, 4, 2), time_duration(22, 59, 59) );
  ptime datetime_2(date(2005, 4, 2), time_duration(23, 0, 0) );

  time_zone_ptr my_zone(new posix_time_zone("STD03DST,M4.1.0,M10.1.0"));

  local_date_time ldt_1(datetime_1, my_zone); // given ptime is UTC
  local_date_time ldt_2(datetime_2, my_zone); // given ptime is UTC

  std::cout << ldt_1.local_time() << std::endl; // "2005-Apr-03 01:59:59" <-
not dst
  std::cout << ldt_2.local_time() << std::endl; // "2005-Apr-03 03:00:00" <-
in dst
}

Current cvs is already capable of this.

Hope this helps,
Bart


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk