php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34771 strtotime() fails with 1-12am/pm
Submitted: 2005-10-07 04:30 UTC Modified: 2005-10-07 10:08 UTC
From: arpad at rajeczy dot com Assigned: derick
Status: Closed Package: Date/time related
PHP Version: 5.1.0RC1 OS: Windows XP
Private report: No CVE-ID:
 [2005-10-07 04:30 UTC] arpad at rajeczy dot com
Description:
------------
strtotime() now returns false for input like '12am', where the minutes are omitted with am, pm, a.m. or p.m.

This should be allowed according to the GNU date input formats: http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html#SEC112

It works correctly in 4.3.10, 4.4.0 and 5.0.4.
It fails in 5.1.0RC1, built Aug 16 2005 13:49:49 and 5.1.0RC2-dev, built Oct 6 2005 20:17:56.

Reproduce code:
---------------
<pre><?php

$tests = array(
    '12am', '1am', '1pm',
    '12a.m.', '1a.m.', '1p.m.',
    '12:00am', '1:00am', '1:00pm',
    '12:00a.m.', '1:00a.m.', '1:00p.m.'
);

foreach ($tests as $test) {
    $t = strtotime($test);
    printf("%-10s => %-15s => %s\n", $test, var_export($t, 1), date('r', $t));
}

?></pre>

Expected result:
----------------
12am       => 1128643200      => Fri, 07 Oct 2005 00:00:00 +0000
1am        => 1128646800      => Fri, 07 Oct 2005 01:00:00 +0000
1pm        => 1128690000      => Fri, 07 Oct 2005 13:00:00 +0000
12a.m.     => 1128643200      => Fri, 07 Oct 2005 00:00:00 +0000
1a.m.      => 1128646800      => Fri, 07 Oct 2005 01:00:00 +0000
1p.m.      => 1128690000      => Fri, 07 Oct 2005 13:00:00 +0000
12:00am    => 1128643200      => Fri, 07 Oct 2005 00:00:00 +0000
1:00am     => 1128646800      => Fri, 07 Oct 2005 01:00:00 +0000
1:00pm     => 1128690000      => Fri, 07 Oct 2005 13:00:00 +0000
12:00a.m.  => 1128643200      => Fri, 07 Oct 2005 00:00:00 +0000
1:00a.m.   => 1128646800      => Fri, 07 Oct 2005 01:00:00 +0000
1:00p.m.   => 1128690000      => Fri, 07 Oct 2005 13:00:00 +0000

Actual result:
--------------
12am       => false           => Thu, 01 Jan 1970 00:00:00 +0000
1am        => false           => Thu, 01 Jan 1970 00:00:00 +0000
1pm        => false           => Thu, 01 Jan 1970 00:00:00 +0000
12a.m.     => false           => Thu, 01 Jan 1970 00:00:00 +0000
1a.m.      => false           => Thu, 01 Jan 1970 00:00:00 +0000
1p.m.      => false           => Thu, 01 Jan 1970 00:00:00 +0000
12:00am    => 1128643200      => Fri, 07 Oct 2005 00:00:00 +0000
1:00am     => 1128646800      => Fri, 07 Oct 2005 01:00:00 +0000
1:00pm     => 1128690000      => Fri, 07 Oct 2005 13:00:00 +0000
12:00a.m.  => 1128643200      => Fri, 07 Oct 2005 00:00:00 +0000
1:00a.m.   => 1128646800      => Fri, 07 Oct 2005 01:00:00 +0000
1:00p.m.   => 1128690000      => Fri, 07 Oct 2005 13:00:00 +0000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-07 09:21 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-10-07 10:09 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.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 02:02:27 2014 UTC