Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2003-05-27 10:07:35

> I have been experimenting with the Boost Date-Time library in the hopes that
> I can use it in an application I am writing. The application deals with

Great :-)

> details omitted...
> For example, the first dose of a
> Measles-Mumps-Rubella (MMR) shot might be required to be given no sooner
> than 6 weeks from the date of the student's birth, and no longer than 2
> months after that (or the shot would be considered overdue). (Note: those
> figures are just made up off the top of my head, but they are useful just
> for the example). Now within that seemingly simple rule, different school
> districts want different levels of flexibility. Some districts want to
> count the last day of the period as the first day that the shot is overdue;

You should consider using the date_period class as a tool in representing
these rules. date_period is nice for checking if a particular date is within
(or outside) a given period. So you can write something generic that checks
if a given date is within the set of notification periods generated by a
rule that calculates one or more periods based on the district rules.

> Th Boost Date-Time library provides several iterators (like week, month, and
> year iterators) that make some of these tasks very easy to compute. Need a
> date 2 months and 1 week from the current date? Create a month iterator,
> std::advance by 2, dereference and create a week iteator, advance by 1,
> ta-da! However, there are some situations that are not so easy. If I need
> to find the date 1 day *before* the date 2 months from my start date, there
> doesn't seem to be an easy way to do it (the iterators are all models of
> Input Iterators, so there is no operator--).

For this I recommend simply postcalculating from the date_itr:

   date one_day_before = *date_itr - date_duration(1);
Note that you might find that you don't really need the iterators here since
you are really only adding the offset once. You should be able to encapsulate
the special rules for calculating offsets. You can see some examples of this
type of code in the underlying calculations for the iterator:

> The ability to create flexible offsets from a given date are extremely
> useful, especially when the units involved are mixed (days, weeks, months,
> years). The ability of the Date-Time library to handle situations like this
> has really impressed me so far, but situations where the offset is a given
> amount of one unit *less* than a given amount of another unit are equally
> important in the application I have in mind. I realize that there are
> larger issues that deal with much smaller and larger time resolutions than I
> am working with, but I would really like to see some of this extra
> flexability make it into the library!

You lost me with this one...


Boost list run by bdawes at, gregod at, cpdaniel at, john at