Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2003-04-30 08:59:31


> Since time_duration uses <long> to represent each of the fields
> (H:M:S:FS), I should be able to add any hour offset to a ptime, as long
> as the resultant ptime is inside the date/time range representable by boost?
>
> With the date ranges of boost being 1400-Jan-1 00:00:00 -> 10000-Jan-1
> 00:00:00, the number of hours between these dates is (very roughly!)
> 7.534E7. This is less than the <long> limit on my system, which is +/-
> 2.147E9. That is good.

Yes, but the resolution of the time_duration is much higher than
hours. Depending on your library configuration it is either
microseconds or nano-seconds. So you need to multiply your
number of hours by 10^6 or 10^9 for the value represented
internally. Internally the duration uses a 64 bit integer.
So, all and all the range is about 2 million hours. The following
program will print out the resolution based on your settings:

#include "boost/date_time/posix_time/posix_time.hpp"
#include <iostream>

//Must match with time_resolutions enum in date_time/time_defs.h
const char* const resolution_names[] = {"Second", "Deci", "Centi", "Milli", "Ten_Thousanth", "Micro", "Nano"};

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

  std::cout << "Resolution: "
            << resolution_names[time_duration::rep_type::resolution()]
            << " -- Ticks per second: "
            << time_duration::rep_type::res_adjust() << std::endl;
  
}

Just to confuse things more there is a bug in 1.29 and 1.30
that causes the conversion calculation to be rounded down to
a long thus limiting the range of the internal calculation.
There is a fix in date_time/time_resolution_traits.hpp in CVS
if you want to patch your install.

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