From:             
Operating system: Linux version 2.6.32-5-amd64
PHP version:      5.3.8
Package:          Date/time related
Bug Type:         Bug
Bug description:Unexpected behaviour while adding or subtracting relative time 
with strtotime

Description:
------------
This problem only exists while using a time zone other than UTC, in my case
"Europe/Berlin".

I have to do relative time calculations and got an unexpected behaviour. I
was "missing" one hour of data and some data was misplaced. First I
assumed, I had forgotten an "UTC" or was using an "date" instead of
"gmdate". Yet it was none of the former. As it turns out, strtotime is
doing something extremely unexpected or even wrong. 

The output consists of five columns, each contains timestamps formatted
with "d H:i \U\T\C"  
- sUnexpectedTimePrevious // minus one minute by strtotime
- sTimePrevious           // minus one minute as it should be
- sTimeNow                // 
- sTimeNext               // plus one minute as it should be
- sUnexpectedTimeNext     // plus one minute by strtotime

Lines with errors are marked with an exclamation marks. One line is of
particular interest:
! 29 23:59 UTC | 30 00:59 UTC | 30 01:00 UTC | 30 01:01 UTC | 30 01:01 UTC
Instead of one hour into the future it's now suddenly two one into the
past. 

For the record, yes I had done a search before submitting this report. I
found #54799 and #53370, yet I feel that the example I submitted might help
analysing the problem.

I am well aware that I could solve my problem by simply switching the
default time zone to "UTC". But this is only solving a symptom, not the
real problem.

sincerely yours
Michael Reetz

Test script:
---------------
//date_default_timezone_set('UTC');          // no problem 
date_default_timezone_set('Europe/Berlin');  // big problem

$iCurrent = strtotime('2011-10-29 23:55:00 UTC');
$iEnd = strtotime('2011-10-30 01:05:00 UTC');
while ($iCurrent <= $iEnd){
        $sTimeNow                = gmdate('d H:i \U\T\C',                      
$iCurrent );
        $sTimePrevious           = gmdate('d H:i \U\T\C',              -60 +   
$iCurrent );
        $sTimeNext               = gmdate('d H:i \U\T\C',               60 +   
$iCurrent );
        $sUnexpectedTimePrevious = gmdate('d H:i \U\T\C', strtotime('- 1
minute',$iCurrent));
        $sUnexpectedTimeNext     = gmdate('d H:i \U\T\C', strtotime('+ 1
minute',$iCurrent));
        
        echo ($sUnexpectedTimePrevious != $sTimePrevious) ? '!':' ';
        echo " $sUnexpectedTimePrevious | $sTimePrevious | $sTimeNow | 
$sTimeNext
| $sUnexpectedTimeNext ";
        echo ($sUnexpectedTimeNext != $sTimeNext) ? '!':' ';
        
        echo "\n";
        $iCurrent += 60;
}

Expected result:
----------------
// created with : date_default_timezone_set('UTC');
  29 23:54 UTC | 29 23:54 UTC | 29 23:55 UTC | 29 23:56 UTC | 29 23:56 UTC
  29 23:55 UTC | 29 23:55 UTC | 29 23:56 UTC | 29 23:57 UTC | 29 23:57 UTC
  29 23:56 UTC | 29 23:56 UTC | 29 23:57 UTC | 29 23:58 UTC | 29 23:58 UTC
  29 23:57 UTC | 29 23:57 UTC | 29 23:58 UTC | 29 23:59 UTC | 29 23:59 UTC
  29 23:58 UTC | 29 23:58 UTC | 29 23:59 UTC | 30 00:00 UTC | 30 00:00 UTC
  29 23:59 UTC | 29 23:59 UTC | 30 00:00 UTC | 30 00:01 UTC | 30 00:01 UTC
  30 00:00 UTC | 30 00:00 UTC | 30 00:01 UTC | 30 00:02 UTC | 30 00:02 UTC
  30 00:01 UTC | 30 00:01 UTC | 30 00:02 UTC | 30 00:03 UTC | 30 00:03 UTC
[.. skipped several lines ..]
  30 00:57 UTC | 30 00:57 UTC | 30 00:58 UTC | 30 00:59 UTC | 30 00:59 UTC
  30 00:58 UTC | 30 00:58 UTC | 30 00:59 UTC | 30 01:00 UTC | 30 01:00 UTC
  30 00:59 UTC | 30 00:59 UTC | 30 01:00 UTC | 30 01:01 UTC | 30 01:01 UTC
  30 01:00 UTC | 30 01:00 UTC | 30 01:01 UTC | 30 01:02 UTC | 30 01:02 UTC
  30 01:01 UTC | 30 01:01 UTC | 30 01:02 UTC | 30 01:03 UTC | 30 01:03 UTC
  30 01:02 UTC | 30 01:02 UTC | 30 01:03 UTC | 30 01:04 UTC | 30 01:04 UTC
  30 01:03 UTC | 30 01:03 UTC | 30 01:04 UTC | 30 01:05 UTC | 30 01:05 UTC
  30 01:04 UTC | 30 01:04 UTC | 30 01:05 UTC | 30 01:06 UTC | 30 01:06 UTC


Actual result:
--------------
// created with : date_default_timezone_set('Europe/Berlin');
  29 23:54 UTC | 29 23:54 UTC | 29 23:55 UTC | 29 23:56 UTC | 29 23:56 UTC
  29 23:55 UTC | 29 23:55 UTC | 29 23:56 UTC | 29 23:57 UTC | 29 23:57 UTC
  29 23:56 UTC | 29 23:56 UTC | 29 23:57 UTC | 29 23:58 UTC | 29 23:58 UTC
  29 23:57 UTC | 29 23:57 UTC | 29 23:58 UTC | 29 23:59 UTC | 29 23:59 UTC
  29 23:58 UTC | 29 23:58 UTC | 29 23:59 UTC | 30 00:00 UTC | 30 01:00 UTC
!
  29 23:59 UTC | 29 23:59 UTC | 30 00:00 UTC | 30 00:01 UTC | 30 01:01 UTC
!
! 30 01:00 UTC | 30 00:00 UTC | 30 00:01 UTC | 30 00:02 UTC | 30 01:02 UTC
!
! 30 01:01 UTC | 30 00:01 UTC | 30 00:02 UTC | 30 00:03 UTC | 30 01:03 UTC
!
[.. skipped several lines ..]
! 30 01:57 UTC | 30 00:57 UTC | 30 00:58 UTC | 30 00:59 UTC | 30 01:59 UTC
!
! 30 01:58 UTC | 30 00:58 UTC | 30 00:59 UTC | 30 01:00 UTC | 30 02:00 UTC
!
! 29 23:59 UTC | 30 00:59 UTC | 30 01:00 UTC | 30 01:01 UTC | 30 01:01 UTC
  30 01:00 UTC | 30 01:00 UTC | 30 01:01 UTC | 30 01:02 UTC | 30 01:02 UTC
  30 01:01 UTC | 30 01:01 UTC | 30 01:02 UTC | 30 01:03 UTC | 30 01:03 UTC
  30 01:02 UTC | 30 01:02 UTC | 30 01:03 UTC | 30 01:04 UTC | 30 01:04 UTC
  30 01:03 UTC | 30 01:03 UTC | 30 01:04 UTC | 30 01:05 UTC | 30 01:05 UTC
  30 01:04 UTC | 30 01:04 UTC | 30 01:05 UTC | 30 01:06 UTC | 30 01:06 UTC


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

Reply via email to