Boost logo

Boost :

From: Friedrich Wilckens (fw_at_[hidden])
Date: 2005-07-21 15:28:08


Hi,

the concept of the length of generic periods puzzles me. The "normal"
case p.length() = p.end() - p.begin() makes sense to me, but why is a
period with last() == begin() treated as a special case, having length
0?

Having this special case make the length concept behave strangely. For
example, [2005-May-1/2005-May-1] has length 0, but
[2005-May-1/2005-May-2] has length 2! Actually there is no period of
length 1 at all.

As I understand from the documentation, the philosophical reason behind
this seems to be that the end points of periods are considered "points"
and that a point and therefore a period that consists of a single point
has zero extension.

This sounds plausible if you think of the periods like intervals on the
real number line. But our situation is different, I think, since we
always deal with discrete quantities that have a finite length (or
"duration").

I would interpret the period [2005-May-1/2005-May-1] as the time period
that lasts during the whole day 2005-May-1, from 00:00 up to
23:59:59.999... Therefore, I would give it the length (duration) 1.

[2005-May-1/2005-Apr-30] would accordingly be an empty period of length
0, and [2005-May-1/2005-Apr-29] would be an invalid period of length -1.

The length of a date_period p would then be simply the number of days in
p, multiplied with the unit of the duration_type. The template parameter
duration_type can be used to defined different measurements of the
length. In the standard case (duration of a day is 1) you measure the
period length in days. But you could also measure it in seconds, by
using a duration_type with unit() = 86400.

What do you think about this?

Sincerely,
Friedrich


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