ID: 33546 Updated by: [EMAIL PROTECTED] Reported By: nickj-phpbugs at nickj dot org -Status: Open +Status: Assigned Bug Type: Date/time related Operating System: Debian Woody GNU/Linux 3.0r6 PHP Version: 5CVS-2005-07-02 (dev) -Assigned To: +Assigned To: derick
Previous Comments: ------------------------------------------------------------------------ [2005-07-02 10:33:33] nickj-phpbugs at nickj dot org Description: ------------ Should strtotime() ignore the weekday for some inputs, rather than treat it as a modifier? Example code: ================================================= <?php print "Should the weekday be treated as part of the time, rather than a modifier?\n"; $input = "Friday July 1 2005 10:00:00 AM"; print "input: " . $input . "\n"; $tStamp = strtotime($input); print "date : " . date ("l F j Y H:i:s A", $tStamp) . "\n\n"; print "Should the weekday be treated as part of the time, rather than a modifier?\n"; $input = "10:00:00 AM Friday July 1 2005"; print "input: " . $input . "\n"; $tStamp = strtotime($input); print "date : " . date ("H:i:s A l F j Y", $tStamp) . "\n"; ?> ================================================= Actual output: ================================================== G:\PHP bugs\php5-win32-200507020230>php.exe ..\weekday-as-time-not-modifier\weekday-as-time-not-modifier.php Should the weekday be treated as part of the time, rather than a modifier? input: Friday July 1 2005 10:00:00 AM date : Friday July 8 2005 10:00:00 AM Should the weekday be treated as part of the time, rather than a modifier? input: 10:00:00 AM Friday July 1 2005 date : 00:00:00 AM Friday July 8 2005 G:\PHP bugs\php5-win32-200507020230> ================================================== What I thought the output would be: ================================================== G:\PHP bugs\php5-win32-200507020230>php.exe ..\weekday-as-time-not-modifier\weekday-as-time-not-modifier.php Should the weekday be treated as part of the time, rather than a modifier? input: Friday July 1 2005 10:00:00 AM date : Friday July 1 2005 10:00:00 AM Should the weekday be treated as part of the time, rather than a modifier? input: 10:00:00 AM Friday July 1 2005 date : 10:00:00 AM Friday July 1 2005 G:\PHP bugs\php5-win32-200507020230> ================================================== Or, to put it another way: strtotime("Friday July 1 2005 10:00:00 AM") gives the same results as strtotime("10:00:00 AM", strtotime("Friday", strtotime("July 1 2005"))), when I would expect it to be equivalent to strtotime("10:00:00 AM", strtotime("July 1 2005")). Note: I'm not sure what I would expect to happen if the weekday was the wrong day (e.g. "Monday July 1 2005 10:00:00 AM"). I think maybe the least surprising thing would be if the weekday was always ignored for these two formats (since it's redundant as it can be determined from the date anyway), same as if the input had been "July 1 2005 10:00:00 AM". And if someone really did then want to use the "Monday" modifier, they could just use strtotime("Monday", strtotime("July 1 2005 10:00:00 AM")) to achieve this. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33546&edit=1