Hi Stas:

On Tue, Aug 23, 2011 at 10:12:19AM -0700, Stas Malyshev wrote:
> >
> >Revision: http://svn.php.net/viewvc?view=revision&revision=315376
> 
> I don't understand this fix. How comes that diff test has:
> 
> test_years_positive__6_shy_1_day: DIFF: 2007-02-06 00:00:00 EST -
> 2000-02-07 00:00:00 EST = **P+6Y11M30DT0H0M0S**
> 
> And the add test has:
> 
> test_years_positive__6_shy_1_day: ADD: 2000-02-07 00:00:00 EST +
> P+6Y11M30DT0H0M0S = **2007-02-06 00:00:00 EST**
> 
> but now sub test has:
> 
> test_years_positive__6_shy_1_day: SUB: 2007-02-06 00:00:00 EST -
> P+6Y11M30DT0H0M0S = **2000-02-05 00:00:00 EST**
> 
> Shouldn't the dates match?

I was wondering the same thing.

The way I figure it, the difference between sub and the other two
functions is which direction the math is done: are you counting days
before/after the end of the first month in the range or the last month
in the range.

Let's walk through the addition:  2000-02-07 + P+6Y11M30D...
  + 6 years   = 2006-02-07
  + 11 months = 2007-01-07
  + 30 days   = 2007-02-06

But the subtraction is:  2007-02-06 - P+6Y11M30D...
  - 6 years   = 2001-02-06
  - 11 months = 2000-03-06
  - 30 days   = 2000-02-05

To make add and sub have the same inputs/outputs, sub would have to take
off days, then months, then years.

While it would be neat if add, diff and sub all came up with the same
answers, changing it now would be a compatibility issue.

Many thanks for reviewing my commits,

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to