Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2003-09-08 07:48:49


Getting back to a couple of issues from last week...

> > On Tue, 02 Sep 2003 19:00:42 -0400, David Abrahams wrote
> >> The "fractional seconds" concept is undocumented. My guess it's
> >> something like:
> >>
> >> x.fractional_seconds() == x.ticks() % seconds(1).ticks()
> >>
> >> This needs to be nailed down.
> >> ...other discussion...
> > 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;
> >
> > }
> >
> > //output
> > Resolution: Micro -- Ticks per second: 1000000
>
> I'm sorry, that's really nasty. Why wouldn't I just do
>
> seconds(1).ticks()

I've added a function to the time duration called ticks_per_second. This
should allow users easy access to do appropriate conversions and should be
much clearer. No docs yet, but this change is in CVS. So you can rewrite the
above as:

   std::cout << " -- Ticks per second: "
             << time_duration::ticks_per_second() << std::endl;

> >> Also, the assymetry of those nice Construction by Count factories
> >> down to nanosec(x) with the accessors which only include units down
> >> to seconds() but not millisec()...nanosec() is disturbing and
> >> frankly inconvenient.
> >
> > Ok, but I'm interested in your use case as once I have a
> > time_duration I don't normally care about a particular sub-second
> > resolution.
>
> OK, well I do. I'm porting some Java code which uses times in whole
> milliseconds, and when a time gets written to disk I need to write
> the number of milliseconds to maintain a compatible format.

For this (just so you don't need to use ticks_per_second) I've added:
  total_milliseconds, total_microseconds, and total_nanoseconds.

So
  nanoseconds(25).total_nanoseconds() == 25
  microseconds(25).total_microseconds() == 25
  milliseconds(25).total_milliseconds() == 25

These will truncate resolutions higher than the requested conversion. For
example:

  nanoseconds(25).total_microseconds() == 0
  nanoseconds(25).total_milliseconds() == 0

Jeff


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