On 17 June 2011 00:51, Stas Malyshev <smalys...@sugarcrm.com> wrote:
> Hi!
>
> I've been looking into various tests and discovered something strange in
> date_diff. Example code:
>
> <?php
> $start = new DateTime('2010-10-04 02:18:48 EDT');
> $end   = new DateTime('2010-11-06 18:38:28 EDT');
> $int = $start->diff($end);
> var_dump($start);
>
> As a result of this I'm getting this:
>
> object(DateTime)#1 (3) {
>  ["date"]=>
>  string(19) "2010-10-04 06:18:48"
>  ["timezone_type"]=>
>  int(2)
>  ["timezone"]=>
>  string(3) "EDT"
> }
>
> As you can see, the date in $start changed, even though it shouldn't happen.
> Looks like it's because of timelib_diff() which has this:
>
>    timelib_apply_localtime(one, 0);
>    timelib_apply_localtime(two, 0);
>
> which converts times in diff arguments to localtime. It then does:
>
>    timelib_apply_localtime(one, 1);
>    timelib_apply_localtime(two, 1);
>
> which is supposed to convert them back, but in fact it does not, since first
> conversion seems to have killed TZ information. I'd propose to fix it by
> making time_diff operate on copies of one and two instead of real
> structures, but maybe somebody has a better idea?


Just ran Stas' script against a lot of 5.3's.

V5.3.0alpha2 :   string(19) "2010-10-04 06:18:48"
V5.3.0alpha3 :   string(19) "2010-10-04 06:18:48"
V5.3.0beta1 :   string(19) "2010-10-04 06:18:48"
V5.3.0RC2 :   string(19) "2010-10-04 06:18:48"
V5.3.0RC3 :   string(19) "2010-10-04 06:18:48"
V5.3.0RC4 :   string(19) "2010-10-04 06:18:48"
V5.3.0 :   string(19) "2010-10-04 06:18:48"
V5.3.1RC1 :   string(19) "2010-10-04 06:18:48"
V5.3.1RC2 :   string(19) "2010-10-04 06:18:48"
V5.3.1RC3 :   string(19) "2010-10-04 06:18:48"
V5.3.1RC4 :   string(19) "2010-10-04 06:18:48"
V5.3.1 :   string(19) "2010-10-04 06:18:48"
V5.3.2RC1 :   string(19) "2010-10-04 06:18:48"
V5.3.2RC2 :   string(19) "2010-10-04 06:18:48"
V5.3.2RC3 :   string(19) "2010-10-04 06:18:48"
V5.3.2 :   string(19) "2010-10-04 06:18:48"
V5.3.3RC1 :   string(19) "2010-10-04 06:18:48"
V5.3.3RC2 :   string(19) "2010-10-04 06:18:48"
V5.3.3RC3 :   string(19) "2010-10-04 06:18:48"
V5.3.3 :   string(19) "2010-10-04 06:18:48"
V5.3.4RC1 :   string(19) "2010-10-04 06:18:48"
V5.3.4RC2 :   string(19) "2010-10-04 06:18:48"
V5.3.4 :   string(19) "2010-10-04 06:18:48"
V5.3.5 :   string(19) "2010-10-04 06:18:48"
V5.3.6RC1 :   string(19) "2010-10-04 06:18:48"
V5.3.6RC2 :   string(19) "2010-10-04 06:18:48"
V5.3.6RC3 :   string(19) "2010-10-04 06:18:48"
V5.3.6 :   string(19) "2010-10-04 06:18:48"


Even though the behaviour is wrong, it is consistent.

There are no user notes commenting on this issue in the documentation.

Can't check the bug base at the moment due to it being down.

If either of the dates use a TLA timezone (EDT, PST, GMT), rather than
the long name (Europe/London, Indian/Kerguelen,
America/Kentucky/Louisville), then that date is altered.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

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

Reply via email to