From:             energie at eox dot hu
Operating system: linux/windows
PHP version:      5.2.9
PHP Bug Type:     Date/time related
Bug description:  date_timezone_set function produces wrong datetime result

Description:
------------
Result of "date_create" with timezon given:
"Mon, 23 May 1955 00:00:00 +0200"
After calling "date_timezone_set" for this date the expected result would
be the same but instead the result is:
"Mon, 23 May 1955 01:00:00 +0200"

In case of "Europe/Budapest" timezone 3 dates are affected between
1900.01.01 and 1999.12.31:
[0] => Sun, 23 May 1954 00:00:00 +0200
[0] => Mon, 23 May 1955 00:00:00 +0200
[0] => Sun, 03 Jun 1956 00:00:00 +0200

There are timezones where everything works fine, and many ohters that have
date inputs that cause this mis-calculation. Thers is no relation between
the dates in different timezones but the wrong dates are always the same in
a given timezone, so there are no "random" errors.

Reproduce code:
---------------
$errors = array();
$timezones = array('Europe/Budapest');
// Uncomment the following line to run on all timezones
// $timezones = timezone_identifiers_list();

function generate_dates($timezone) {
  $dates = array();
  for($y = 1900; $y <= 1999; $y++) {
    for($m = 1; $m <= 12; $m++) {
      for($d = 1; $d <= 31; $d++) {
        $date = date_create(sprintf('%s-%s-%s 00:00:00', $y, $m, $d),
timezone_open($timezone));
        if ($date) {
          $dates[] = $date;
        }
      }
    }
  }
  return $dates;
}

foreach($timezones as $timezone) {
  $dates = generate_dates($timezone);
  foreach($dates as $date) {
    $test = date_format($date, 'r');
    date_timezone_set($date, timezone_open($timezone));
    if ($test != date_format($date, 'r')) {
      $errors[$timezone][] = array($test, date_format($date, 'r'));
    }
  }
  print('Timezone: '. $timezone . ', errors: '. count($errors[$timezone])
. "\n");
  // Uncomment the following line to display all dates that calculated
"wrong"
  // print_r($errors[$timezone]);
  // print "\n";
}

Expected result:
----------------
Timezone: Europe/Budapest, errors: 0

Actual result:
--------------
Timezone: Europe/Budapest, errors: 3

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

Reply via email to