php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52143 strtotime() unexpectedly changed from 5.2.13 to 5.3.2 breaking alot of scripts
Submitted: 2010-06-22 13:01 UTC Modified: 2013-01-16 11:05 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jason dot woods at blueyonder dot co dot uk Assigned: googleguy (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.2 OS: CentOS 5.5 x86_64
Private report: No CVE-ID: None
 [2010-06-22 13:01 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-05 03:40 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2010-09-24 02:57 UTC] 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-09-27 10:49 UTC] derick@php.net
-Status: Assigned +Status: To be documented -Assigned To: derick +Assigned To:
 [2010-09-27 10:49 UTC] derick@php.net
The new behaviour is correct; this was a bug fix.
 [2012-12-08 16:19 UTC] sonnenberg at gmail dot com
I have a similar problem, but I'm calculating with weeks and am getting inconsistent results.

Test script:
------------
<?php
echo strftime("%Y %W", strtotime("-1 week", strtotime("2013W01"))) . "\n";
echo strftime("%Y %W", strtotime("+1 week", strtotime("2012W52"))) . "\n";
echo gmdate("Y W", strtotime("2012W53")) . "\n";
echo strftime("%Y %W", strtotime("2012W53")) . "\n";
echo date("Y W", strtotime("2012W53")) . "\n";
?>

Expected result:
----------------
2012 53
2012 53
2012 53
2012 53
2012 53

Actual result:
--------------
2012 52
2012 53
2012 52
2012 53
2012 01 - this one is particulary interesting...

I've tried different timezones, but that does not seem to affect this issue as I get the same output for all timezones.

php version:
------------
PHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli) (built: Sep 12 2012 18:59:41)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
 [2012-12-10 01:54 UTC] aharvey@php.net
This was meant to be a documentation problem, I gather. Changing the bug type to get it on the doc team radar.

@sonnenberg: I'd suggest hitting up one of the many support channels available for PHP. The bug tracker isn't a support forum, and your issue isn't particularly related to this bug (short version: ISO week numbers don't work the way you necessarily expect in terms of the last week of the year).
 [2012-12-10 01:54 UTC] aharvey@php.net
-Type: Bug +Type: Documentation Problem -Package: Date/time related +Package: Documentation problem
 [2013-01-16 11:04 UTC] googleguy@php.net
Automatic comment from SVN on behalf of googleguy
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=329158
Log: Updated changelog for strtotime's relative week changes. Fixes bug #52143.

This affects Derick's commits for 357292a098f572bc7baf11a8438314072af6c00b and 089bc254eb33b3c42418f869f2478ce35558c9ea in PHP 5.3, which change this behavior.
 [2013-01-16 11:05 UTC] googleguy@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: googleguy
 [2013-01-16 11:05 UTC] googleguy@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 13:01:26 2024 UTC