Bug #52143 [Asn->Tbd]: strtotime() unexpectedly changed from 5.2.13 to 5.3.2 breaking alot of scripts

From: Date: Mon, 27 Sep 2010 08:49:30 +0000
Subject: Bug #52143 [Asn->Tbd]: strtotime() unexpectedly changed from 5.2.13 to 5.3.2 breaking alot of scripts
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-154666@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52143&edit=1

 ID:                 52143
 Updated by:         derick@php.net
 Reported by:        jason dot woods at blueyonder dot co dot uk
 Summary:            strtotime() unexpectedly changed from 5.2.13 to
                     5.3.2 breaking alot of scripts
-Status:             Assigned
+Status:             To be documented
 Type:               Bug
 Package:            Date/time related
 Operating System:   CentOS 5.5 x86_64
 PHP Version:        5.3.2
-Assigned To:        derick
+Assigned To:        
 Block user comment: N

 New Comment:

The new behaviour is correct; this was a bug fix.


Previous Comments:
------------------------------------------------------------------------
[2010-09-24 02:57:19] kkcagg at gmail dot com

Bug also shows up in PHP version 5.3.3. 
It seems to be normalizing the value to the Monday of the target week.
For example: strtotime('next week') would be equivalent to
strtotime('Monday next 
week') instead of the expected 
value of the current time plus the number of seconds in a week.

------------------------------------------------------------------------
[2010-06-22 13:01:38] jason dot woods at blueyonder dot co dot uk

Description:
------------
In version 5.2.13 the following code:
<?php
echo ($now = strtotime('+1 day')) . ' - ' . date('d-m-Y H.i.s', $now)
.
"\n";
echo ($last = strtotime('last week', $now)) . ' - ' . date('d-m-Y
H.i.s', $last) . "\n";
echo ($next = strtotime('+1 week', $last)) . ' - ' . date('d-m-Y
H.i.s',
$next) . "\n";
?>

Gives the following result:
1277283067 - 23-06-2010 09.51.07
1276678267 - 16-06-2010 09.51.07
1277283067 - 23-06-2010 09.51.07

That is, first line is current time.
Second time is "last week", otherwise known as "-1 week".
Third time is "+1 week", which reverses the change that the "-1 week"
did.

However, this changed in 5.3.2 and it now gives the following result:
1277281904 - 23-06-2010 09.31.44
1276504304 - 14-06-2010 09.31.44
1277109104 - 21-06-2010 09.31.44

So it appears "last week" is no longer the equivalent of "-1 week".

Is this a deliberate change or something that was broken in 5.3.2?

I have been unable to test other versions and can only give you the
difference from 5.2.13 and 5.3.2.

Thanks.

Test script:
---------------
<?php
echo ($now = strtotime('+1 day')) . ' - ' . date('d-m-Y H.i.s', $now)
.
"\n";
echo ($last = strtotime('last week', $now)) . ' - ' . date('d-m-Y
H.i.s', $last) . "\n";
echo ($next = strtotime('+1 week', $last)) . ' - ' . date('d-m-Y
H.i.s',
$next) . "\n";
?>

Expected result:
----------------
1277283067 - 23-06-2010 09.51.07
1276678267 - 16-06-2010 09.51.07
1277283067 - 23-06-2010 09.51.07

Actual result:
--------------
1277281904 - 23-06-2010 09.31.44
1276504304 - 14-06-2010 09.31.44
1277109104 - 21-06-2010 09.31.44


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52143&edit=1


Thread (5 messages)

« previous php.bugs (#154666) next »