php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66257 strtotime doesn't use current timezone on '4 thursdays'
Submitted: 2013-12-10 18:09 UTC Modified: 2022-05-13 13:59 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mfaust at usiwireless dot com Assigned: derick (profile)
Status: Duplicate Package: Date/time related
PHP Version: 5.6.8 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: mfaust at usiwireless dot com
New email:
PHP Version: OS:

 

 [2013-12-10 18:09 UTC] mfaust at usiwireless dot com
Description:
------------
---
From manual page: http://www.php.net/function.strtotime
---
date_default_timezone_set('UTC');
$timestamp = mktime(0,0,0,11,1,2014);

strtotime('4 thursdays', $timestamp) does not return the same timestamp as strtotime('first thursday + 3 weeks', $timestamp)

The first call returns a timestamp indicating a time of 6am (we are in CST) and the second returns a timestamp indicating 12am.

Test script:
---------------
//The server timezone is America/Chicago
$timestamp = mktime(0,0,0,11,1,2014);
echo strtotime('4 thursdays', $timestamp) . "\n";
strtotime('first thursday + 3 weeks', $timestamp) . "\n";

Expected result:
----------------
Both should return the same timestamp indicating 12:00 am.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-10 18:30 UTC] derick@php.net
-Status: Open +Status: Feedback
 [2013-12-10 18:30 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

The following works just fine here:
<?php
date_default_timezone_set("America/Chicago");
$timestamp = mktime(0,0,0,11,1,2014);
$a = strtotime('4 thursdays', $timestamp);
$b = strtotime('first thursday + 3 weeks', $timestamp);

echo date(DateTime::ISO8601, $a), "\n";
echo date(DateTime::ISO8601, $b), "\n";
?>

outputs:
2014-11-27T00:00:00-0600
2014-11-27T00:00:00-0600


This is with PHP 5.4.24
 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2014-12-30 16:49 UTC] mfaust at usiwireless dot com
This still occurs on PHP 5.6.4

<?php
echo date_default_timezone_get() . "\n;
date_default_timezone_set('UTC');
$timestamp = mktime(0,0,0,11,1,2014);
echo strtotime('4 thursdays', $timestamp) . "\n";
echo strtotime('first thursday + 3 weeks', $timestamp) . "\n";
?>

Output:
America/Chicago
1417068000
1417046400
 [2014-12-30 16:52 UTC] mfaust at usiwireless dot com
I am unable to change the status back to "unopened" due to "ERROR:
You aren't allowed to change a bug to that state."
 [2014-12-30 16:52 UTC] mfaust at usiwireless dot com
sorry, I meant "re-opened"
 [2014-12-30 18:54 UTC] requinix@php.net
-Status: No Feedback +Status: Open
 [2015-04-29 19:58 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-04-29 19:58 UTC] cmb@php.net
Interestingly, the issue is timezone related. It doesn't happen for
America/Chicago, but for UTC, for instance[1].

[1] <http://3v4l.org/LLkCE>
 [2015-04-29 19:59 UTC] cmb@php.net
-PHP Version: 5.4.22 +PHP Version: 5.6.8
 [2015-04-29 20:05 UTC] derick@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: derick
 [2021-07-28 11:21 UTC] d at ja dot vu
Plural of day names are not supported by timelib, so '4 thursdays' will be interpreted as:

'the fourth Thursday, in the "s" - sierra - time zone'

The sierra time zone is UTC-6, and that overlaps with America/Chicago for parts of the year.

I think this should be reclassified as a documentation problem.

The claim on the strtotime page that it will 'Parse about any English textual datetime description into a Unix timestamp' is not very specific, and other time units do support the plural form. It could do with a few more examples, or a pointer to the regexes used in the implementation.

Alternatively I can provide a few-line patch to add the plural of week names, but that will break BC.

However I do not think many people even know about the one letter time zones, except for Zulu, and even fewer will actually use it.

In any case I suggest the test case for this bug be removed from the test suite.
 [2021-10-01 14:08 UTC] cmb@php.net
> Plural of day names are not supported by timelib, […]

Spot on!  Thank you for the detailed analysis!

> It could do with a few more examples, or a pointer to the
> regexes used in the implementation.

There is already documentation about the supported date and time
formats[1], and this page is linked from the parameter's
description.  It seems to me that adding the parameter name to the
function description, so that it'll be linked to the parameter's
description, should be sufficient.

> In any case I suggest the test case for this bug be removed from
> the test suite.

Good catch!  <https://github.com/php/php-src/pull/7543>

[1] <https://www.php.net/manual/en/datetime.formats.php>
 [2022-05-13 13:59 UTC] derick@php.net
-Status: Assigned +Status: Duplicate
 [2022-05-13 13:59 UTC] derick@php.net
Support for "thursdays" (with the extra "s") will be part of PHP 8.1.8 and PHP 8.2 once there is a new timelib release with https://github.com/derickr/timelib/commit/cb26187fb6033a80d4bae4883ee6b62eebfd4856 in it.

This makes this issue a duplicate of #51934, and hence I'm closing it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 08 03:01:28 2024 UTC