php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40037 Incorrect output from strtotime, when timestr is used with a relative term this
Submitted: 2007-01-05 19:30 UTC Modified: 2007-04-24 13:40 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: shruti224 at yahoo dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.2.0 OS: ES4
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: shruti224 at yahoo dot com
New email:
PHP Version: OS:

 

 [2007-01-05 19:30 UTC] shruti224 at yahoo dot com
Description:
------------
Sample script to demonstrate the issue:

<?php
  print "14:00:0 UTC this Friday [" . strtotime("14:00:0 UTC this Friday") . "]\n";
  print "this Friday UTC [" . strtotime("this Friday UTC") . "]\n";
  print "now UTC from strtotime [" . strtotime("now UTC") . "]\n";
?>

When I used this same script with :
"PHP 5.0.5 (cli) (built: Oct 29 2006 22:42:15)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.5, Copyright (c) 1998-2004 Zend Technologies"

and my System's date being:
# date
Fri Jan  5 14:21:38 EST 2007

I got the correct desired output, which is as follows:

14:00:0 UTC this Friday [1168005600]
this Friday UTC [1167955200]
now UTC from strtotime [1168006899]

After upgrading to PHP 5.2 
"PHP 5.2.0 (cli) (built: Jan  2 2007 12:44:27)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies"

and system's date now being

# date
Fri Jan  5 14:23:00 EST 2007

The same script as above generated the following incorrect output:

14:00:0 UTC this Friday [1167955200]
this Friday UTC [1167955200]
now UTC from strtotime [1168006981]

By the look of it, it seems as if it ignores the time string completely.

Please let me know, if I need to provide any further information. 



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-05 19:39 UTC] shruti224 at yahoo dot com
The following line in the sample script is used purely for demonstration purpose to give the idea to the developer of the  test system's current time in UTC. 

print "now UTC from strtotime [" . strtotime("now UTC") . "]\n";

The bug occurs when strtotime is invoked with a pattern containing timestr and a relative term ("this Friday") in my example.
 [2007-04-13 08:17 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The new parser is slightly more advanced and actually takes order into account, which means that:

14:00:0 - will set the time to 14:00
UTC     - sets the timezone to UTC
this Friday - sets the time to the start of this friday, which is 00:00

if you change the timestring to:
"this Friday 14:00:0 UTC"

it works properly. As I think this is the more correct behaviour (and more flexible in the end) - it's too stay.
 [2007-04-24 13:40 UTC] shruti224 at yahoo dot com
Does this mean that the new parser in 5.2.0 is not backwards compatible?  
It dint work the way you mentioned in PHP 5.0.x.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC