php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33546 Should strtotime() ignore the weekday for some inputs? (not treat as modifier)
Submitted: 2005-07-02 10:33 UTC Modified: 2005-10-19 23:11 UTC
From: nickj-phpbugs at nickj dot org Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5CVS-2005-07-02 (dev) OS: Debian Woody GNU/Linux 3.0r6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nickj-phpbugs at nickj dot org
New email:
PHP Version: OS:

 

 [2005-07-02 10:33 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-07 23:46 UTC] derick@php.net
We can not easily ignore weekday names in strings at arbitrary places in the way the current scanner works now. Changing it to allow for this means more more rigid formats are supported only, losing a lot of complexity in the code and less flexibility.
 [2005-10-10 04:09 UTC] nickj-phpbugs at nickj dot org
Fair enough. I only noticed this in passing, and wondered about it, but I understand your logic and I agree it's not worth making the code more brittle for this case, when people can instead just remove the day-of-the-week string to get the correct results.
 [2005-10-19 23:11 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-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 23:01:32 2024 UTC