Bug #55575 [NEW]: strtotime() returns erroneous result on nonsense DATE_RSS format date strings

From: Date: Sat, 03 Sep 2011 04:04:09 +0000
Subject: Bug #55575 [NEW]: strtotime() returns erroneous result on nonsense DATE_RSS format date strings
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-163268@lists.php.net to get a copy of this message
From:             
Operating system: Linux & Darwin
PHP version:      5.3.8
Package:          Date/time related
Bug Type:         Bug
Bug description:strtotime() returns erroneous result on nonsense DATE_RSS format date strings

Description:
------------
(Note: I was only able to test on 5.2.16, 5.3.0, and 5.3.4.  Since there is
no 
evidence of it being fixed in the changelog of 5.3.8, I assume it's still
there.)

The ninth of May, 2010, was a Sunday.  However, if you assert to
strtotime() that 
it was a Monday, it will return the Unix timestamp for Monday, May 10th. 
Likewise 
if you assert the ninth was a Tuesday, it will return the timestamp for the
11th; 
a Wednesday the 12th, and so on right up to returning a Unix timestamp for

Saturday, 15 May 2010 if you provide it with "Saturday, 9 May 2010".

Presumably, the correct behavior is one of (1) to throw an error given a
self-
contradictory date, (2) to return nothing at all, or (3) to ignore the
day-of-the-
week element and return the Unix timestamp for the date specified (e.g. 9
May 
2010).  Returning the timestamp for another date altogether is wrong.

Test script:
---------------
$datestring="9 May 2010 04:24:36 GMT";
print "\"\": ".strtotime($datestring)." ".date($dateformat,
strtotime($datestri\
ng)) ."\n";

$datestring="Sun, 9 May 2010 04:24:36 GMT";
print "Sun: ".strtotime($datestring)." ".date($dateformat,
strtotime($datestrin\
g)) ."\n";

$datestring="Mon, 9 May 2010 04:24:36 GMT";
print "Mon: ".strtotime($datestring)." ".date($dateformat,
strtotime($datestrin\
g)) ."\n";

$datestring="Tue, 9 May 2010 04:24:36 GMT";
print "Tue: ".strtotime($datestring)." ".date($dateformat,
strtotime($datestrin\
g)) ."\n";


Expected result:
----------------
"": 1273379076 Sun, 09 May 2010 00:24:36 -0400
Sun: 1273379076 Sun, 09 May 2010 00:24:36 -0400
Mon: 1273379076 Sun, 09 May 2010 00:24:36 -0400
Tue: 1273379076 Sun, 09 May 2010 00:24:36 -0400

(Alternatively:


"": 1273379076 Sun, 09 May 2010 00:24:36 -0400
Sun: 1273379076 Sun, 09 May 2010 00:24:36 -0400
Mon: 
Tue: 
)

Actual result:
--------------
"": 1273379076 Sun, 09 May 2010 00:24:36 -0400
Sun: 1273379076 Sun, 09 May 2010 00:24:36 -0400
Mon: 1273465476 Mon, 10 May 2010 00:24:36 -0400
Tue: 1273551876 Tue, 11 May 2010 00:24:36 -0400

-- 
Edit bug report at https://bugs.php.net/bug.php?id=55575&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=55575&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=55575&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=55575&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=55575&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55575&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=55575&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=55575&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=55575&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=55575&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=55575&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=55575&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=55575&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=55575&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=55575&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=55575&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55575&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=55575&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=55575&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=55575&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=55575&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=55575&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#163268) next »