php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55015 strToTime calculates wrong date
Submitted: 2011-06-09 14:13 UTC Modified: 2011-07-06 05:01 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cp at ltur dot de Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cp at ltur dot de
New email:
PHP Version: OS:

 

 [2011-06-09 14:13 UTC] cp at ltur dot de
Description:
------------
Hi,

strToTime calculates a "Wednesday" when i asked for a "Monday".

php 5.3.6
Configure Command =>  './configure'  '--disable-cgi' '--with-libedit'
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,NTS
PHP Extension Build => API20090626,NTS


Test script:
---------------
// today Y-m-d 2011-06-09 
date_default_timezone_set('Europe/Berlin');
echo date('Ymd N', strToTime('next month next Monday'));



Expected result:
----------------
20110711 1

Actual result:
--------------
20110713 3

Patches

calc_rel_weekday_after_month_year_test (last revision 2011-07-06 06:08 UTC by lonnyk at gmail dot com)
calc_rel_weekday_after_month_year (last revision 2011-07-06 06:08 UTC by lonnyk at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-01 04:52 UTC] lonnyk at gmail dot com
I also found that if you are using this code and the next Monday is in the next 
month then the month will advance two months. I set the date to 20110630 and ran 
the exact same test script:

lonny@lonnydev:~/php/php-src-5.3$ sudo date -s "30 JUN 2011 10:00:00"
Thu Jun 30 10:00:00 EDT 2011
lonny@lonnydev:~/php/php-src-5.3$ php ~/test.php 
20110804 4
 [2011-07-06 02:10 UTC] lonnyk at gmail dot com
The problem is that the relative weekday was calculated before the relative 
month/year. I attached a batch and a test to change the order of the calculation.
 [2011-07-06 03:41 UTC] cp at ltur dot de
Hi,

i applied the patch from lonny and it works for me :-)

php > date_default_timezone_set('Europe/Berlin');
php > echo date('Ymd N', strToTime('next month next Monday', mktime(0,0,0,6,9,2011)));

// prints
20110711 1

Will somebody commit his patch?

kind regards
.cp
 [2011-07-06 05:01 UTC] derick@php.net
-Status: Open +Status: Wont fix
 [2011-07-06 05:01 UTC] derick@php.net
We can't just randomly change the order because other people may rely on it. What you want to do is really this:

$date = date_create("2011-06-09 00:00:00")->modify("next month")->modify("next monday");
 [2011-07-06 05:47 UTC] cp at ltur dot de
Hi Derick,

> We can't just randomly change the order because other people may rely on it.

I understand this, but it is still a bug. It should be mentioned in the strToTime() documentation along with the workaround you posted, so people use the function with care.

kind regards
.cp
 [2011-07-06 09:33 UTC] lonnyk at gmail dot com
Hi,

I do not know if it matters, but this bug was created when the order was changed 
in rev #213026
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC