|
Boost : |
From: Dave Gomboc (dave_at_[hidden])
Date: 2001-12-17 12:11:59
> class time:
> - Represents an absolute point in time.
> - The time of the day can be specified in hours, minutes, seconds and
> nanoseconds.
> - The date can be specified with the Gregorian calendar, support for
> other calendars can easily be added without modifying the time class.
> - Any point in time from about 4000BC until about 50000 years in the
> future can be represented.
> - Text I/O is done through functions provided by
> std::time_get/std::time_put facets (only the range of std::tm is
> therefore supported).
>
> class timespan (or time_span if you prefer):
> - Represents a period of time (or the difference between two points
> in time). Can be specified in days, hours, minutes, seconds and
> nanoseconds
> - Supports time spans of up to about 29000 years (positive or
> negative).
While the use of a single, instantaneous datetime seems ubiquitous, my
personal experience is that it always ends up being annoying as soon as
something a touch more complicated needs to be done. In cases where
there isn't a really good reason not to (e.g. storing a large amount of
datetime data contraindicates this practice), I use a datetime_interval
even when representing a basic unit of datetime (e.g. December 17, 2001,
if the resolution is days). I think this keeps my code cleaner.
I don't really know why people don't treat datetime_interval as the
fundamental abstraction, rather than datetime_instant. Formerly the
idea of a half-open range might have seemed a bit obscure, but that
shouldn't be the case for today's C++ programmer.
BTW, there's a template-based datetime facility being prepared, I'm sure
someone mentioned it below. It allows for user-defined accuracy, which
I think is a good idea.
Dave Gomboc
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk