From: Jeff Garland (jeff_at_[hidden])
Date: 2003-08-07 08:02:23
On Wed, 6 Aug 2003 10:11:20 -0700, Stephan T. Lavavej wrote
> [Jeff Garland]
> > The downside of this is that when you are printing a time duration:
> > std::cout << td.hours() << ':' << td.minutes() << ':' << td.seconds();
> > you have to take remove the sign from the minutes and seconds.
> > I have a third suggestion:
> > - Implement (1) using abs() in the hours() method
> > - Add a total_seconds function to the library so you don't have to write
> > it.
>[Stephan T. Lavavej]
> How about:
> * Implement (2), making all components negative if the time_duration
> is negative * Add a total_seconds() fxn so users don't have to write
> it * Allow users to lexical_cast<string> a time_duration so it can
> be printed as "-5:34:22" and document this so that users don't try
> to roll their own naively.
I believe to_simple_string does what you are suggesting so you shouldn't need
> Some unrelated issues that have come to me while working with date_time:
> * The documentation could stand some revision. There's apparently daylight
> saving time stuff in the code, but it's not documented at all.
Yes, the DST part of the library is under experiment and revision which
is why there is a lack of documentation.
> * It's also not obvious from the documentation where things like
> January and Tuesday live. This applies generally; it's not obvious
> what namespace many functions and classes live in.
Ok. The answer is there are 3 namespaces: boost::date_time,
boost::gregorian, and boost::posix_time. boost::date_time is where
'time system independent' or reuseble components live. boost::gregorian and
boost::posix_time are 'instances' of a set of compatible temporal types and
related classes built from the components in boost::date_time. Mostly they
are comprised of typedefs of templates in boost::date_time and selection of
specific implementations (eg: selecting the size integer to use for the time
duration). So January ends up living in both date_time and gregorian. You can
imagine needing it to build 'MyAlternativeDateSystem' and wanting the enum for
> * I looked at the code and determined that Sunday = 0 (it's an
> enumeration), but it'd be nice if this were guaranteed in the
> * One example shows:
> last_kday_of_month lkm(Monday,Jan);
> date d = lkm.get_date(2002);//2002-Jan-28
> I found that I had to write:
> first_kday_of_month<date>(Sunday, Apr).get_date(2002)
This was a bug (missing typedef) that has been fixed. If you update your
boost/date_time/gregorian/gregorian_types.hpp you will pick it up.
> Shouldn't the fact that first_kday_of_month and its ilk are
> templated be documented? I was confused why I have to template it
> on date in the first place (what else would go there?).
Well sure, but virtually everything in the library is a template so that isn't
going to help much.
If you want to see more about what is under the hood I recommend looking at:
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk