I quote from perldoc DateTime:
################################### START
How Date Math is Done
It's important to have some understanding of how date math is
implemented in order to effectively use this module and
"DateTime::Duration".
The parts of a duration can be broken down into four parts. These are
months, days, minutes, and seconds. Adding one month to a date is
different than adding 4 weeks or 28, 29, 30, or 31 days. Similarly, due
to DST and leap seconds, adding a day can be different than adding
86,400 seconds, and adding a minute is not exactly the same as 60
seconds.
"DateTime.pm" always adds (or subtracts) days, then months, minutes, and
then seconds. If there are any boundary overflows, these are normalized
at each step.
This means that adding one month and one day to February 28, 2003 will
produce the date April 1, 2003, not March 29, 2003.
my $dt = DateTime->new( year => 2003, month => 2, day => 28 );
$dt->add( months => 1, days => 1 );
# 2003-04-01 - the result
On the other hand, if we add months first, and then separately add days,
we end up with March 29, 2003:
$dt->add( months => 1 )->add( days => 1 );
# 2003-03-29
############################################### END
To me it appears DateTime does provide a method to add/subtract duration
methods to use what you call LSB ( days then months ) and MSB (months then
days)
----- Original Message -----
From: "Rick Measham" <[EMAIL PROTECTED]>
To: "renard" <[EMAIL PROTECTED]>; "datetime" <datetime@perl.org>
Sent: Tuesday, June 14, 2005 7:32 PM
Subject: Re: DT::Duration behaviour .. LSB or MSB?
renard wrote:
When subtracting or adding months, DateTime does not know whether a month
has 28, 29, 30, or 31 days. It simply subtract/add the number of
specified months.
renard, you missed the point of my post. I'm asking about LSB vs MSB
subtraction.
With LSB subtraction, we subtract the Least Significant Bit first
(normally that's 'bit' as in 'byte', in this case it's 'bit' as in
'piece'). In DateTime, that's nanoseconds. So if we want to subtract
00:01:00.000000001 (1 hour, 1 nanosecond) we start by subtracting the
nanosecond, then we subtract the hour.
With MSB subtraction we subtract the Most Significant Bit first. In
DateTime, that's years, then months, days, hours, etc down to nanoseconds.
The reason this is significant is demonstrated in my previous post, but
here it is without code:
Imagine January 1st at midnight. Subtract 1 month, 14 days:
MSB: January 1 - 1 month = December 1
December 1 - 14 days = November 17
LSB: January 1 - 14 days = December 18
December 18 - 1 month = November 18
At some stage it appears DT:D has changed from one to the other.
I'm asking that we create two subtraction/addition functions: add_lsb and
add_msb (and their more relevent counterpoints subtract_lsb and
subtract_msb). We then decide which is the preffered method (IMHO, MSB)
and set in stone that that is the way we work. The standard subtract
function is then just an alias to subtract_msb() and the standard add
function is an alias to add_msb().
Cheers!
Rick Measham