php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36638 strtotime unconditional false return on now <= 0
Submitted: 2006-03-06 22:27 UTC Modified: 2006-03-06 22:45 UTC
From: mikeb at tracersinfo dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.1.2 OS: Win32 (XP2) and Linux
Private report: No CVE-ID: None
 [2006-03-06 22:27 UTC] mikeb at tracersinfo dot com
Description:
------------
Despite recent modifications to the date functions that now allow negative timestamps in both of my environments (Win32 and Linux) [THANK YOU, btw!], strtotime() returns false any time the "now" parameter evaluates to 0 or less, even when it clearly demonstrates it can perform the calculation requested and the date/time in question is within reasonable bounds.

Reproduce code:
---------------
<?php

$a["mktime(1, 2, 3, 4, 5, 1967)"] = mktime(1, 2, 3, 4, 5, 1967);
$a["strtotime('-10 years', 0)"] = strtotime('-10 years', 0);
$a["strtotime('-10 years', 1)"] = strtotime('-10 years', 1);
$a["strtotime('+10 years', 0)"] = strtotime('+10 years', 0);
$a["strtotime('+10 years', 1)"] = strtotime('+10 years', 1);
$a["gmmktime(0, 0, 0, 1, 1, 1970)"] = gmmktime(0, 0, 0, 1, 1, 1970);
$a["strtotime('-10 years', gmmktime(0, 0, 0, 1, 1, 1970))"] = strtotime('-10 years', gmmktime(0, 0, 0, 1, 1, 1970));
$a["strtotime('12/31/1969 19:00:00 -10 years')"] = strtotime('12/31/1969 19:00:00 -10 years');
$a["strtotime('+10 years', gmmktime(0, 0, 0, 1, 1, 1965))"] = strtotime('+10 years', gmmktime(0, 0, 0, 1, 1, 1965));
$a["strtotime('12/31/1964 19:00:00 +10 years')"] = strtotime('12/31/1964 19:00:00 +10 years');
var_dump($a);

?>

Expected result:
----------------
array(10) {
  ["mktime(1, 2, 3, 4, 5, 1967)"]=>
  int(-86551077)
  ["strtotime('-10 years', 0)"]=>
  int(-315619200)  <------
  ["strtotime('-10 years', 1)"]=>
  int(-315619199)
  ["strtotime('+10 years', 0)"]=>
  int(315532800)  <-------
  ["strtotime('+10 years', 1)"]=>
  int(315532801)
  ["gmmktime(0, 0, 0, 1, 1, 1970)"]=>
  int(0)
  ["strtotime('-10 years', gmmktime(0, 0, 0, 1, 1, 1970))"]=>
  int(-315619200)  <------
  ["strtotime('12/31/1969 19:00:00 -10 years')"]=>
  int(-315619200)
  ["strtotime('+10 years', gmmktime(0, 0, 0, 1, 1, 1965))"]=>
  int(157766400)  <------
  ["strtotime('12/31/1964 19:00:00 +10 years')"]=>
  int(157766400)
}

Actual result:
--------------
array(10) {
  ["mktime(1, 2, 3, 4, 5, 1967)"]=>
  int(-86551077)
  ["strtotime('-10 years', 0)"]=>
  bool(false)  <------
  ["strtotime('-10 years', 1)"]=>
  int(-315619199)
  ["strtotime('+10 years', 0)"]=>
  bool(false)  <------
  ["strtotime('+10 years', 1)"]=>
  int(315532801)
  ["gmmktime(0, 0, 0, 1, 1, 1970)"]=>
  int(0)
  ["strtotime('-10 years', gmmktime(0, 0, 0, 1, 1, 1970))"]=>
  bool(false)  <------
  ["strtotime('12/31/1969 19:00:00 -10 years')"]=>
  int(-315619200)
  ["strtotime('+10 years', gmmktime(0, 0, 0, 1, 1, 1965))"]=>
  bool(false)  <------
  ["strtotime('12/31/1964 19:00:00 +10 years')"]=>
  int(157766400)
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-06 22:29 UTC] derick@php.net
I'll have a look at it.
 [2006-03-06 22:45 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.

Fixed in CVS, the fix will be in the upcoming 5.1.3.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC