|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2001-12-17 22:53:57
> One other point: how do you represent, for instance, just a time but
> with no particular date? This is surely just as common as a specific
> point in time, and is a sort of specialisation of a "recurring
> date/time": 10:30AM every day, every hour on the hour, every monday
> at noon, the 4th thursday of every november (or whenever it is all
> those strange people celebrate thanksgiving). I'm not sure if you
> could justify having a standard library component to represent this
> concept, but it's certainly a useful abstraction, even outside of
> crontab files.
This is a very common problem, and there are all sorts of variations to
represent. The best way of dealing with these I have found is to build them
using function objects. The reason for the function object is that a typical
use for these "generators" is to specify some part of the date-time, then supply
some additional concrete part(s), and apply a function to generate one or more
concrete date-times.
So for example, I currently have a class partial_date (this is a bad name, BTW)
that constructs with just a month and day. Then if you call get_date(year) then
you get a concrete date returned. Of course if you specified 2/29 and then pass
a non-leap year, you need to get an exception or NotADate. As for the recurring
event concept I have a different generator template called recurring_interval
that handles this concept. As for the holiday thing, in Caledrical Calculations
http://emr.cs.iit.edu/home/reingold/calendar-book/first-edition-index.shtml most
of these holiday calculations get done with a single function (nth-kday -- eg:
calculate 3rd thursday of november for a specific year).
BTW, I really like your example -- I'll have to see if I can emulate a crontab
spec...
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk