Boost logo

Boost Users :

From: Jeff Garland (jeff_at_[hidden])
Date: 2006-09-20 15:08:59


Arkadiy Vertleyb wrote:
> Hi,
>
> I am looking at the possibility of replacing our custom-made datetime
> classes with the ones from boost::date_time. The library looks very
> attractive to me, and I would certainly go ahead and use it... however
> there is (at least) one catch, and this is the snap-to-end-of-month behavior
> of the months duration, according to which:
>
> {2000-Feb-29} + {1 month} = {2000-Mar-31}
>
> The problem is that it contradicts to the XSD spec we are using,
> http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#adding-durations-to-dateTimes,
> that says that months must be just "pinned to be within range". Maybe there
> is (could be added) some sort of policy, that could be used to achieve this
> behavior?

I've tried to read this algorithm before and I have to say I've never fully
understood it. As for policies, the implementation is already policy based.
You could write a new month_functor class to replace the one that the library
uses. The signature is

   template<class date_type>
   class month_functor
   {
   public:
     duration_type get_offset(const date_type& d) const
     {}
     duration_type get_neg_offset(const date_type& d) const
     {}

Where get_neg_offset handles subtraction and get_offset is for addition. You
can see date_time/adjust_functors.hpp for the current implementation. After
you write your new function you'll need to create your own duration types or
replace the ones in date_time/gregorian/greg_duration_types.hpp so that you
can do cool stuff like:

   date d(2000,3,31);
   d += months(3);

Jeff


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net