php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42489 Quirk in strtotime using 'next' relative keyword
Submitted: 2007-08-30 15:50 UTC Modified: 2009-05-03 14:09 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: chet at somedec dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2CVS-2008-10-24 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chet at somedec dot com
New email:
PHP Version: OS:

 

 [2007-08-30 15:50 UTC] chet at somedec dot com
Description:
------------
Adding time (even zero) to a relative date using the "next" keyword fails.

Reproduce code:
---------------
<?php
    $day = date("l"); // Get what /today/ is.
    $plain = strtotime("Next $day");
    $zweek = strtotime("Next $day + 0 weeks");
    $incweek = strtotime("Next $day + 1 week");
    $zmin = strtotime("Next $day + 0 weeks");
    $incmin = strtotime("Next $day + 1 minute");
    echo "Today is $day\n";
    echo "Next $day is " . date(DATE_ATOM, $plain) . "\n";
    echo ($zweek === $plain ? "PASS\t" : "FAIL\t") . "Next $day + 0 weeks is " . date(DATE_ATOM, $zweek) . "\n";
    echo ($incweek !== $plain ? "PASS\t" : "FAIL\t") . "Next $day + 1 week is " . date(DATE_ATOM, $incweek) . "\n";
    echo ($zmin === $plain ? "PASS\t" : "FAIL\t") . "Next $day + 0 minutes is " . date(DATE_ATOM, $zmin) . "\n";
    echo ($incmin == ($plain + 60) ? "PASS\t" : "FAIL\t") . "Next $day + 1 minute is " . date(DATE_ATOM, $incmin) . "\n";
?>

Expected result:
----------------
The four tests should pass; none do.

Actual result:
--------------
Using the current day (according to your computer clock) in conjunction with the next keyword (i.e. "Next Thursday" when run on Thursday) correctly returns one week from the current date. However, adding or subtracting any amount of time results in an erroneous result of the /current date/ plus or minus the offset.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-03 10:50 UTC] jani@php.net
Assigned to the ext/date maintainer. :)
 [2008-05-13 03:38 UTC] toby dot matejovsky at gmail dot com
The same problem occurs on PHP 5.2.5 on Mac OS 10.5.
 [2008-10-24 16:15 UTC] jani@php.net
Still fails.
 [2009-05-03 14:08 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

This is fixed for PHP 5.3, I get the correct output:

Today is Sunday
Next Sunday is 2009-05-10T00:00:00+02:00
PASS	Next Sunday + 0 weeks is 2009-05-10T00:00:00+02:00
PASS	Next Sunday + 1 week is 2009-05-17T00:00:00+02:00
PASS	Next Sunday + 0 minutes is 2009-05-10T00:00:00+02:00
PASS	Next Sunday + 1 minute is 2009-05-10T00:01:00+02:00

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC