#42489 [Opn->Csd]: Quirk in strtotime using 'next' relative keyword

From: Date: Sun, 03 May 2009 14:09:41 +0000
Subject: #42489 [Opn->Csd]: Quirk in strtotime using 'next' relative keyword
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-136673@lists.php.net to get a copy of this message
 ID:               42489
 Updated by:       derick@php.net
 Reported By:      chet at somedec dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Date/time related
 Operating System: *
 PHP Version:      5.2CVS-2008-10-24
 Assigned To:      derick


Previous Comments:
------------------------------------------------------------------------

[2009-05-03 14:08:23] 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


------------------------------------------------------------------------

[2008-10-24 16:15:15] jani@php.net

Still fails.

------------------------------------------------------------------------

[2008-05-13 03:38:34] toby dot matejovsky at gmail dot com

The same problem occurs on PHP 5.2.5 on Mac OS 10.5.

------------------------------------------------------------------------

[2007-09-03 10:50:31] jani@php.net

Assigned to the ext/date maintainer. :)

------------------------------------------------------------------------

[2007-08-30 15:50:24] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42489&edit=1



Thread (7 messages)

« previous php.bugs (#136673) next »