Bug #53539 [Opn->Nab]: strtotime off-by-1-week bug still not fixed
| From: | levim@php.net | Date: | Mon, 19 Nov 2012 02:55:27 +0000 |
| Subject: | Bug #53539 [Opn->Nab]: strtotime off-by-1-week bug still not fixed | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9179@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53539&edit=1
ID: 53539
Updated by: levim@php.net
Reported by: kugel at rci dot rutgers dot edu
Summary: strtotime off-by-1-week bug still not fixed
-Status: Open
+Status: Not a bug
Type: Bug
Package: Documentation problem
Operating System: Fedora
PHP Version: 5.3SVN-2010-12-13 (SVN)
Block user comment: N
Private report: N
New Comment:
As noted by derick, you need to use the "of" keyword to link the relative and
absolute formats.
Previous Comments:
------------------------------------------------------------------------
[2010-12-13 19:13:29] kugel at rci dot rutgers dot edu
The corrected datestring works on my personal 5.3.3 machine, but not on my dreamhost (PHP 5.2.14)
host; that shows as "Wed, Dec 31 1969". I did find a note in the datetime documentation
suggesting relative formats were broken before 5.3, so I think everything is now explained or noted.
------------------------------------------------------------------------
[2010-12-13 17:29:47] derick@php.net
This is not a *code* bug though.
It works like follows:
"January 2011 8:00pm" is an absolute date string, which processed first:
$ php -r 'echo date("Y-m-d H:i:s", strtotime("January 2011 8:00pm"));'
2011-01-01 20:00:00
$ php -r 'echo strtotime("January 2011 8:00pm");'
1293912000
"first Saturday" is a string relative to the absolute date string, which is processed
next:
$ php -r 'echo date("Y-m-d H:i:s", strtotime("first Saturday",
1293912000));'
2011-01-08 00:00:00
You are missing the "of" keyword, which links the two together:
$ php -r 'echo date("Y-m-d H:i:s", strtotime("first Saturday of January 2011
8:00pm")), "\n";'
2011-01-01 20:00:00
$ php -r 'echo date("Y-m-d H:i:s", strtotime("third Saturday of January 2011
8:00pm")), "\n";'
2011-01-15 20:00:00
------------------------------------------------------------------------
[2010-12-13 17:01:37] kugel at rci dot rutgers dot edu
better bug title
------------------------------------------------------------------------
[2010-12-13 16:59:43] kugel at rci dot rutgers dot edu
Description:
------------
---
From manual page: http://www.php.net/function.strtotime#Changelog
---
"5.2.7 In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month
where that weekday was the first day of the month would incorrectly add one week to the returned
timestamp. This has been corrected in 5.2.7 and later versions."
Contrary to the above, this bug still exists in PHP 5.2.13, 5.2.14, and 5.3.3.
Test script:
---------------
<?php
date_default_timezone_set("America/New_York");
echo date("D, M j Y", strtotime("first Saturday January 2011 8:00pm")) .
"\n";
echo date("D, M j Y", strtotime("third Saturday January 2011 8:00pm")) .
"\n";
?>
Expected result:
----------------
Sat, Jan 1 2011
Sat, Jan 15 2011
Actual result:
--------------
Sat, Jan 8 2011
Sat, Jan 22 2011
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53539&edit=1