Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2003-06-20 08:13:43


On Thu, 19 Jun 2003 17:15:11 -0400, Stefan Seefeld wrote
> little precision:
>
> the posix_time::time_duration type seems to come close to
> what I want. However, the documentation isn't very clear on
> what 'fractional_seconds()' actually stands for.

fractional_seconds is a count. It is relative to the resolution the
time_duration supports. So if the time_duration supports 'tenths of
seconds' then fractional_seconds value of 1 is 1/10 of a second.
In this configuration the maximum value fractional seconds would
return is 9 since 10 rolls over to a new second.

With the standard configuration the count will be the number of
nano seconds. To get this you have to define a macro
BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG. This is discussed on
the BuildInfo page:

http://www.crystalclearsoftware.com/libraries/gdtl/user_docs/BuildInfo.html

Anyway, you can find out the resolution you are using with
this code:

#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;
  
}

> Does the 'unit()' function return 1 unit expressed in nanoseconds ?
> If so, why is it returning a time_duration and not a long (say) ?

It returns 1 unit in whatever the resolution of the time duration is.
This is used so that the 'time_period' can generically increment a time
period without needing to know the resolution of the time_duration.

Jeff


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