Boost logo

Boost :

From: Friedrich Wilckens (fw_at_[hidden])
Date: 2005-07-22 15:22:56


On Thu, 2005-07-21 at 21:01 -0700, Jeff Garland wrote:

<skip>

> > For example, [2005-May-1/2005-May-1] has length 0,
>
> Well, that seems incorrect [2005-May-1/2005-May-1) has length zero (Note the
> non-inclusive end). But, then again, what is the duration of [1,1] -- zero I
> believe.
>
> > 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").
>
> Actually, I don't think it is different from an 'integer numberline'.
>
> > 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.
>
> Yes, that seems correct except that a date-period cannot represent anything
> less than a single day. Just as integers in a range [1,1] cannot represent
> 1.99999.

> Jeff

I'm somewhat confused and I fear we don't quite understand each other.
Let me try to clarify.

If you interpret the periods as subsets of the integer number line Z, so
that date_periods are sets of days, you get into troubles, for it is
unclear what the "openness" of the intervals should mean. For example,
[1, 2) = [1, 1] = {1}, [1, 3) = [1, 2] = {1, 2}, and so on. Z with the
usual distance metric carries the discrete topology, i.e., *every*
subset is open and closed. You would get a consistent system if you
define the length of [a, b + 1) = [a, b] as b -a (i.e., last() -
begin()). Then, a single day period [a, a + 1) would indeed have length
0, and [1, 3) would have length 1 (not 2).

What I had in mind is a different interpretation, and I believe it
better captures what we have in mind when we use the periods. I consider
periods as intervals on the real number line R. Now, a day is not a
"point" on R, it is an interval itself. I would (as I said above) treat
it as the right-open interval lasting from 00:00 to 23:59:59.999....
Similar, a second like 2005-May-1 10:13:30 is a right-open interval,
lasting from 10:13:30.0 until 10:13:30.9999... The points of R are time
instances with zero duration, whereas a second has a duration of, well,
a second.

What *is* a point on R is the moment at which a day starts. We have a
little confusion here since in notations like [2005-May-1, 2005-May-2),
"2005-May-1" does not refer to the whole day, but to its start, so it
should be considered as a shorthand for 2005-May-1 00:00:00.0; likewise
for 2005-May-2.

In this interpretation, a date_period is is not a set of days, but a
union of days. It lasts from the begin of its starting day to the end of
its last day. It is a truly half-open interval, so [2005-May-1,
2005-May-2) is different from the closed interval [2005-May-1,
2005-May-2] (though they have the same length); it is also different
from the closed interval [2005-May-1, 2005-May-1] which is a single
point of length 0. The interpretation as half-open intervals is built
into the semantics of date_period, so closed intervals cannot be
expressed at all. [2005-May-1, 2005-May-1) can be expressed and is the
empty set (of length 0).

begin() returns the first day (not its starting point) contained in the
date_period, and last() returns its last day (again, not its starting
point).

The length of a period can generally be defined as end() - begin() (not
as last() - begin() as in the Z-interpretation above). It turns out that
[2005-May-1, 2005-May-2) just describes the whole day 2001-May-1 and has
length 1. [2005-May-1, 2005-May-1) is the empty set and has length 0.

In this interpretation, time_periods (based on ptime) are likewise
subsets of R. The difference is only that time_periods allow a much
finer resolution. Every date_period could be expressed as a time_period.
For time periods, we can ask if a certain microsecond (again, this is
not a point, but a half-open interval of finite length) is contained in
it; for date_periods, days are the smallest objects we consider.

Sorry, this email became somewhat lengthy, but I do not know how to
express what I mean with fewer words.

Sincerely,
Friedrich


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