Edit report at https://bugs.php.net/bug.php?id=51051&edit=1

 ID:                 51051
 Comment by:         kavi at postpro dot net
 Reported by:        mehdi dot rande at aliasource dot fr
 Summary:            DateTime modify wrong result with DST change
 Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        5.3.1
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

This is still broken in 5.3.21, according to danielc's test.

$ php --version
PHP 5.3.21 (cli) (built: Jan 17 2013 12:34:34) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

$ php derp.php 

SPRING INTERVALS (add okay, sub does not change hour)
  2010-03-14T01:59:59-05:00  America/New_York  EST  0  1268549999
Adding interval: PT1S
  2010-03-14T03:00:00-04:00  America/New_York  EDT  1  1268550000
Subtracting interval: PT1S
  2010-03-14T03:59:59-04:00  America/New_York  EDT  1  1268553599

SPRING TIMESTAMPS (works as expected)
  2010-03-14T01:59:59-05:00  America/New_York  EST  0  1268549999
Adding seconds: 1
  2010-03-14T03:00:00-04:00  America/New_York  EDT  1  1268550000
Subtracting seconds: 1
  2010-03-14T01:59:59-05:00  America/New_York  EST  0  1268549999

FALL INTERVALS (add and sub skip the 1am - 2am redo)
  2010-11-07T00:59:59-04:00  America/New_York  EDT  1  1289105999
Adding interval: PT1H
  2010-11-07T01:59:59-04:00  America/New_York  EDT  1  1289109599
Adding interval: PT1S
  2010-11-07T02:00:00-05:00  America/New_York  EST  0  1289113200
Subtracting interval: PT1S
  2010-11-07T01:59:59-04:00  America/New_York  EDT  1  1289109599

FALL TIMESTAMPS (works as expected)
  2010-11-07T00:59:59-04:00  America/New_York  EDT  1  1289105999
Adding seconds: 3600
  2010-11-07T01:59:59-04:00  America/New_York  EDT  1  1289109599
Adding seconds: 1
  2010-11-07T01:00:00-05:00  America/New_York  EST  0  1289109600
Adding seconds: 3600
  2010-11-07T02:00:00-05:00  America/New_York  EST  0  1289113200
Subtracting seconds: 1
  2010-11-07T01:59:59-05:00  America/New_York  EST  0  1289113199


Previous Comments:
------------------------------------------------------------------------
[2012-05-17 00:12:04] kavi at postpro dot net

See also:

https://bugs.php.net/bug.php?id=60960
https://bugs.php.net/bug.php?id=61530
https://bugs.php.net/bug.php?id=52480

Quoting https://wiki.php.net/rfc/datetime_and_daylight_saving_time -- "Getting 
these issues straightened out before 5.4 goes into Release Candidate status 
seems 
wise."

------------------------------------------------------------------------
[2012-03-14 14:36:41] webmaster at martinandersson dot com

DateTime::diff get's it wrong in PHP 5.4. Tested on Apache (with PHP 5.4 VC9) / 
Windows 7 x64. Code of horror:

$d1 = new DateTime("2011-10-30 01:05:00", new DateTimeZone("Europe/Stockholm"));
$d2 = new DateTime("2011-10-30 03:05:00", new DateTimeZone("Europe/Stockholm"));

$di = $d1->diff($d2);
echo $di->h;

This produces '2' whereas it should have said '3' because in this timezone and 
interval (more precisly 03:00:00), all Swedes turned their clock back 1 hour. 
Still, the internal logic of PHP 5.4 knows about the different offsets:

echo $d1->getOffset() / (60 * 60);

Prints '2'.

echo $d2->getOffset() / (60 * 60);

Prints '1'.

A direct calculation with UNIX timestamps produces the correct result:

$hoursofdiff = ($d2->getTimeStamp() - $d1->getTimeStamp()) / 60 / 60;
echo "Calculated difference in hours: $hoursofdiff";

Prints '3'.

This issue has been further elaborated here:
http://stackoverflow.com/questions/9695870/phps-datetimediff-gets-it-wrong

------------------------------------------------------------------------
[2011-11-21 02:43:15] dani...@php.net

This will be addressed by
https://wiki.php.net/rfc/datetime_and_daylight_saving_time

------------------------------------------------------------------------
[2011-04-18 17:30:09] halde at freenet dot de

reproduced issue of previous poster on a linux machine (timestamps are not 
equal):

$ php -a
Interactive shell

php > $dt = new DateTime('now', new DateTimeZone('Europe/Berlin'));
php > $dt->setTimestamp(1288483200);
php > echo $dt->getTimestamp();
1288486800
php > echo phpversion();
5.3.3-1ubuntu9.3
php > exit

$ uname -a
Linux wum128229 2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:39:03 UTC 2011 
x86_64 GNU/Linux

------------------------------------------------------------------------
[2011-02-24 17:07:56] j dot ek at gmx dot net

Think I found a related issue, reproduce it with:

<?php
$dt = new DateTime('now', new DateTimeZone('Europe/Berlin'));

//  try to set timestamp of 2010-10-31T02:00:00+0200
$dt->setTimestamp(1288483200);

// but returns timestamp of 2010-10-31T02:00:00+0100
echo $dt->getTimestamp(); // outputs 1288486800
?>

WinXP 32, PHP 5.3.2 (cli) (built: Mar  3 2010 20:36:54)

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=51051


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=51051&edit=1

Reply via email to