Boost logo

Boost Users :

From: Alberto Giannetti (albertogiannetti_at_[hidden])
Date: 2006-11-15 10:41:10


I want to calculate the time difference between local_date_time objects that I
initialized using two different time zones:

#include <iostream>

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/local_time/local_time.hpp> // TZ database

int main(int argc, char* argv[])
{
  using namespace boost::posix_time;
  using namespace boost::local_time;

  tz_database tz_db;
  try {
        tz_db.load_from_file("tz.csv");
  } catch( data_not_accessible& e ) {
        std::cerr << "Error with time zone data file: " << e.what() << std::endl;
        exit(EXIT_FAILURE);
  } catch( bad_field_count& e ) {
        std::cerr << "Error with time zone data file: " << e.what() << std::endl;
        exit(EXIT_FAILURE);
  }

  time_zone_ptr tzp_nyc = tz_db.time_zone_from_region("America/New_York");
  time_zone_ptr tzp_rome = tz_db.time_zone_from_region("Europe/Rome");

  local_date_time nyc_time(second_clock::universal_time(), tzp_nyc);
  std::cout << "Current time in NY is " <<
to_simple_string(nyc_time.local_time()) << std::endl;

  local_date_time rome_time(second_clock::universal_time(), tzp_rome);
  std::cout << "Current time in Rome is " <<
to_simple_string(rome_time.local_time()) << std::endl;

  local_time_period tdiff(nyc_time, rome_time);
  std::cout << "Difference between time zones: " << tdiff.length() <<
std::endl;

  return 0;
}

tdiff.lenth() returns 00:00:00. Why the function can't return the difference
between the two local times?

 
____________________________________________________________________________________
Sponsored Link

$420k for $1,399/mo.
Think You Pay Too Much For Your Mortgage?
Find Out! www.LowerMyBills.com/lre


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