php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16429 strtotime fails when crossing Daylight Saving Time
Submitted: 2002-04-04 09:28 UTC Modified: 2003-01-17 22:09 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:2 (40.0%)
From: sveinp at basefarm dot no Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 4.3.0-dev OS: Solaris/Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-04-04 09:28 UTC] sveinp at basefarm dot no
[sveinp@ws195 ~]$ php -q
<?PHP
print strftime("%c",strtotime("last saturday")) . "\n";
?>
Fri Mar 29 23:00:00 2002
[sveinp@ws195 ~]$

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-04 13:40 UTC] eru@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.


----
To be totally sure, that this is indeed a bug, please use a fresher version of PHP and retest it then.

Thanks for your help!

 [2002-07-04 14:54 UTC] sniper@php.net
Reproduced with PHP 4.3.0-dev.

 [2002-08-19 13:55 UTC] iliaa@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

I've just tried this on PHP 4.3.0-dev on linux and the function appears to work fine.
 [2002-08-19 15:15 UTC] msopacua at idg dot nl
Please reset to open.
If this was to be closed it, would be 'close' and not 'bogus', as Jani already confirmed it.

Today's checkout, HEAD and STABLE:
mdev@server21 ~/cvs/php4
$ sapi/cli/php -q
<?php
$today = mktime(9, 28, 0, 4, 4, 2002);
print date("r", $today) . "\n";
print date("r", strtotime("last saturday", $today)) . "\n";
?>
Thu,  4 Apr 2002 09:28:00 +0200
Fri, 29 Mar 2002 23:00:00 +0100

mdev@server21 ~/cvs/php-4.2.3
$ sapi/cli/php -q
<?php
$today = mktime(9, 28, 0, 4, 4, 2002);
print date("r", $today) . "\n";
print date("r", strtotime("last saturday", $today)) . "\n";
?>
Thu,  4 Apr 2002 09:28:00 +0200
Fri, 29 Mar 2002 23:00:00 +0100
 [2002-08-19 16:36 UTC] sniper@php.net
So it was fixed by some change. Not bogus, I could reproduce it.

 [2002-08-19 17:18 UTC] sniper@php.net
Oops..the original script by sveinp@basefarm.no works now..but the example by msopacua@idg.nl does not..

 [2002-08-19 17:22 UTC] rasmus@php.net
Works for me.  I get:

Thu,  4 Apr 2002 09:28:00 -0800
Sat, 30 Mar 2002 00:00:00 -0800
 [2002-08-19 17:25 UTC] ilia at prohost dot org
Works fine for me as well, with PHP 4.3.0-dev <1 hour old

Thu,  4 Apr 2002 09:28:00 -0500
Sat, 30 Mar 2002 00:00:00 -0500
 [2002-08-19 19:07 UTC] msopacua at idg dot nl
Rasmus, Ilia.
Please look at your results: The timezone is the same, as there was no DST jump in that weekend for you.

http://www.timeanddate.com/time/dstevents.html
 
Please try for one week later.
 [2002-08-22 12:39 UTC] ilia at prohost dot org
<?php
$today = mktime(9, 28, 0, 4, 7, 2002);
print date("r", $today) . "\n";
print date("r", strtotime("last saturday", $today)) . "\n";
?>
------------

Sun,  7 Apr 2002 09:28:00 -0400
Sat,  6 Apr 2002 00:00:00 -0500


Seems to work fine, even across DST.
 [2002-08-22 12:42 UTC] ilia at prohost dot org
After a few more tests I was able to replicate the problem, it appears that if I set the date higher then the date on which the change occurs, the functions messes up.

For example:
<?php
$today = mktime(9, 28, 0, 4, 8, 2002);
print date("r", $today) . "\n";
print date("r", strtotime("last saturday", $today)) . "\n";
?>
------------
Mon,  8 Apr 2002 09:28:00 -0400
Fri,  5 Apr 2002 23:00:00 -0500
 [2003-01-02 19:52 UTC] nicos@php.net
Please try using this CVS snapshot:

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


 [2003-01-17 22:09 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2003-04-01 09:12 UTC] swek at gmx dot net
PHP version 4.3.1

reused the code found here recently.

<?php
$today = mktime(9, 28, 0, 4, 1, 2003);
print date("r", $today) . "<BR>";
print date("r", strtotime("last saturday", $today)) . "<BR>";
print date("r", strtotime("last sunday", $today)) . "<BR>";
print date("r", strtotime("last monday", $today)) . "<BR>";
?>

Tue, 1 Apr 2003 09:28:00 +0200
Fri, 28 Mar 2003 23:00:00 +0100
Sat, 29 Mar 2003 23:00:00 +0100
Mon, 31 Mar 2003 00:00:00 +0200

how to handle this? 
everything before monday seems to get 1 day less.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC