Boost logo

Boost Users :

From: willw_at_ais (willw_at_[hidden])
Date: 2003-03-20 12:30:51


I am updating an old 1992-style application that previously used
time_t based time to produce trend graphs of logged data. I am putting
in ptime instead, and have come unstuck.

The time range of the X-axis in this app is essentially
under user control. It can show any period from a few seconds (sub
seconds in the new version) up to three years. The labels on the x
axis are placed at sensible points for the current range. For example
if the graph shows 30 minutes, the ticks on the axis occur at 5 minute
intervals; if it is displaying a week they occur on day boundaries.

The old version of the program achieves this label placing by using
the % operator and doing arithmetic with the seconds that underly
time_t. I would like to do something similar with ptime. My attempt
went like this:

// Get next time (>= start) which falls on an itvl boundary
ptime GetNextBoundary2(const ptime& start, const time_duration& itvl)
{
// Use 1/1/1970 as a base - not ideal but good enough for this
        const ptime origin(date(1970,1,1));
        time_duration start_offset = start - origin;
        return ptime (start + itvl -
                nanosec(start_offset.ticks() % itvl.ticks()));
}

This fails because - among other reasons - although I can get ticks
out, nanosec() won't put them back in again. I guess it is normalising
on the way in?

I feel sure I am going about this the wrong way, but am baffled as to
what I should do next.

All help gratefully received. Please be gentle with me - I am
essentially a Pascal programmer who is busking, and finding this C++
template stuff hard.

TIA

Will Watts
AIS Ltd


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