On 2012.3.2 3:35 PM, David Nicol wrote:
> It seems that the root of the difficulty is an exclusivity that there can only
> be one date representing each day. The canonical date. Calling February 1 by
> the name January 32 is "wrong" and if you don't stop it, they won't let you
> enter third grade, or something. Silly authoritatians.
> 
> If months are day offsets into the year, and day-of-month is the additional
> days to add to the offset, and this approach is applied to smaller levels too,
> all the screwey questions can fall into place.  A year after 29 feb is 1 mar
> of the following year.

First off, DateTime already does resolve this problem just the way you suggest
by separating date *math* from setting a date.  Math works just the way you
suggest.

   $dt = DateTime->new( year => 2012 => month => 8, day => 31 );
   print $dt;                        # 2012-08-31T00:00:00
   print $dt->add( months => 1 )     # 2012-10-01T00:00:00

If you're going to tell DateTime you want "September 31, 2012" I'm ok with it
telling you "that does not exist" because you specifically asked for a date
that does not exist.  If you ask for "a month after Aug 31, 2012" that's a
perfectly valid thing for a human to ask it's going to do some interpretation.

The problem is the docs don't make this distinction clear.


As a side note, the issue of date math is not simple and it's not because of
some prissy adherence to calendar boundaries.  It is, in fact, the calendar
itself that is the problem.  It leads to some absurd results that violate our
normal mathematical axioms.  For example...

Feb 29, 2012  + 1 year = March 1, 2013
March 1, 2012 + 1 year = March 1, 2013

Two different dates, add the same thing, two different results.  It's like
saying 2 + 2 is 4 and 3 + 2 is 4.  You might say "that's just because of the
leap year".  Nope.

August 31, 2012 + 1 month = Oct 1, 2012
Sept 1, 2012    + 1 month = Oct 1, 2012

The fundamental problem is "month" and "year" and even "day" (DST changes) do
not represent the same amount of absolute time when added to different dates.
 You might say "I can live with that".  But then you have to answer this:

March 1, 2013   - 1 year  = ?
Oct 1, 2012     - 1 month = ?

Date math is not commutative and this leads to all sorts of problem.  They
cannot be dismissed as some silly authoritarian demand.


-- 
The mind is a terrible thing,
and it must be stopped.

Reply via email to