On Wed, 7 Sep 2005 [EMAIL PROTECTED] wrote:
Dave Rolsky said:
The more I think about this the more I'm convinced that the idea of
datetime subtraction producing something other than seconds is a
convenient fiction. Similarly, date subtraction producing something other
than a count of days is full of potential bugs.
I agree .. let DateTime::Duration just result in these two units so that:
Date - Date = d Days
Time - Time = s Seconds
DateTime - DateTime = (Date - Date) + (Time - Time) = d Days + s Seconds
Of course, then there's the normalization question:
2005-09-10T12:54 - 2005-09-09T12:57 =
a) 1 days, -180 seconds
b) 86397 seconds
Previously I campaigned for no mixing of negative/positive values in
durations, but now I'd prefer the first option. That way, DST won't matter
so much. On DST change-over I can still add 1 day, -180 seconds to 12:57
and end up on the next day at 12:54. With the second option I'd end up at
1:54 or 11:54.
This is somewhat appealing. Of course, you're still depending on a
certain ordering of additions (days before seconds), I think. The fact
that the ordering is fixed still creates situations where operations are
not reversible.
And yes, I know you've suggested offering many orderings, but that just
means that users have to understand all of them and determine which one to
use for every case, which basically translates to unusability.
I guess the first option is the equivelent of the 'Local' arithmetic and
the second is the equiv of UTC arithmetic.
I guess. You didn't say which timezone, but I'm guessing
Australia/Melbourne.
If we limit durations to these two units (days, seconds) then everything
else can be done in DT:F:Duration... You have 30 days, your base is
November 1st, the number of 'months' in this duration is 1. It's December
1st, there's zero months..
I'm not campaigning to see a Duration limited to these two units, just a
substraction resulting in them. A duration can have 3 months, 1 hour.
DT:F:Duration will be able to do a 'normalize' without any
parsing/formatting which will mean that our 30 days from Nov 1st can be
turned into a Month if that's what you tell DT:F:Duration that's how you
want it.
Yeah, having subtraction return just these units, _and_ allowing mixed
durations, does seem appealing given the alternatives. It allows for
subtraction to follow the same mixed UTC/local logic as add_duration,
which is cool, and I think it makes the "endpoint +/- duration = other
endpoint" formula hold true in all cases.
The downside is it's a semi-radical change to existing behavior, and
basically forces the use of DT::Format::Duration to get what you current
get. But that's not so bad, I guess.
-dave
/*===================================================
VegGuide.Org www.BookIRead.com
Your guide to all that's veg. My book blog
===================================================*/