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

 ID:                 54799
 Updated by:         [email protected]
 Reported by:        robertoherreros at gmail dot com
 Summary:            Incorrect results when operating with time on DST
                     changes
-Status:             Assigned
+Status:             Duplicate
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        5.3.6
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

This is a duplicate of https://bugs.php.net/bug.php?id=51051


Previous Comments:
------------------------------------------------------------------------
[2011-05-18 08:34:47] robertoherreros at gmail dot com

One more thing:

// BAD
// 2011-03-27, 02:00:00 -> 03:00:00
// Expected: 2011-03-27 03:30:00, Actual: 2011-03-27 02:30:00
// 2011-03-27 02:30:00 don't exists
$tz = new DateTimezone('Europe/Madrid');
$d = new DateTime('2011-03-27 02:30:00',$tz);
echo $d->format('Y-m-d H:i:s').'<br/>';

------------------------------------------------------------------------
[2011-05-17 16:57:51] robertoherreros at gmail dot com

Description:
------------
Incorrect results when operating with time on DST changes.

Operations like: '-1 hour', '-1 min' or setTime()

In order to resolve the problem, all operations with time must be done in 
timestamp directly.

Test script:
---------------
// 2011-03-27, 02:00:00 -> 03:00:00 
$tz = new DateTimezone('Europe/Madrid');
$d = new DateTime('2011-03-28 02:30:00',$tz);

// OK
// One day early
// Result: 2011-03-27 03:30:00
echo $d->modify('-1 day')->format('Y-m-d H:i:s').'<br/>';

// BAD
// One hour early (or other TIME operation)
// Expected: 2011-03-27 01:30:00, Actual: 2011-03-27 03:30:00
echo $d->modify('-1 hour')->format('Y-m-d H:i:s').'<br/>';

// BAD
// SetDate and setTime
// Expected: 2011-03-27 03:30:00, Actual: 2011-03-27 02:30:00
echo $d->setDate(2011,3,27)->setTime(2,30,0)->format('Y-m-d H:i:s').'<br/>';

// OK
// Set timezone again after setDate and setTime fix the above problem
// Result: 2011-03-27 03:30:00
echo $d->setDate(2011,3,27)->setTime(2,30,0)->setTimezone($tz)->format('Y-m-d 
H:i:s').'<br/>';

// OK
// One hour early but changing timestamp
// Result: 2011-03-27 01:30:00
echo $d->setTimestamp(($d->getTimestamp()-3600))->format('Y-m-d H:i:s').'<br/>';

// OK
// One hour after
// Result: 2011-03-27 03:30:00
echo $d->modify('2011-03-27 01:30:00')->modify('+1 hours')->format('Y-m-d 
H:i:s').'<br/>';


// BAD
// Two hours after
// Expected: 2011-03-27 04:30:00, Actual: 2011-03-27 03:30:00
echo $d->modify('2011-03-27 01:30:00')->modify('+2 hours')->format('Y-m-d 
H:i:s').'<br/>';

Expected result:
----------------
2011-03-27 03:30:00
2011-03-27 01:30:00
2011-03-27 03:30:00
2011-03-27 03:30:00
2011-03-27 01:30:00
2011-03-27 03:30:00
2011-03-27 04:30:00

Actual result:
--------------
2011-03-27 03:30:00
2011-03-27 03:30:00
2011-03-27 02:30:00
2011-03-27 03:30:00
2011-03-27 01:30:00
2011-03-27 03:30:00
2011-03-27 03:30:00


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



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

Reply via email to