Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0a4

Bug #18417 Date_Span changes timezone silently
Submitted: 2011-03-31 20:54 UTC
From: dumb Assigned:
Status: Open Package: Date (version 1.5.0a1)
PHP Version: 5.1.6 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2011-03-31 20:54 UTC] dumb (Dumb Terminal)
Description: ------------ When using Date_Span with the setFromDateDiff() method the 2 given Date objects will have their timezones siliently changed to UTC. I understand that a date needs to be converted into UTC before any calculation is performed, but the state of the objects passed into the method should not be affected afterwards. A Possible solution could be to clone the objects, then perform the timezone alteration and caculation on the clones. fialing that you could just change the times zones back after the calculations. ps. This is similar to: http://pear.php.net/bugs/bug.php?id=6435&edit=2 But the problem is caused by: Span.php: function setFromDateDiff($date1, $date2) { if (!is_a($date1, 'date') or !is_a($date2, 'date')) { return false; } $date1->toUTC(); $date2->toUTC(); ..etc.. Expected result: ---------------- Before date span: event1 info: 2011-03-31 16:44:59 Europe/London event2 info: 2011-03-31 16:44:59 Europe/London After date span: event1 info: 2011-03-31 16:44:59 Europe/London event2 info: 2011-03-31 16:44:59 Europe/London Actual result: -------------- Before date span: event1 info: 2011-03-31 16:44:59 Europe/London event2 info: 2011-03-31 16:44:59 Europe/London After date span: event1 info: 2011-03-31 15:44:59 UTC event2 info: 2011-03-31 15:44:59 UTC

Comments

 [2011-03-31 20:55 UTC] dumb (Dumb Terminal)
Example test: <?php require_once "Date.php"; $date1 = new Date(); $date2 = new Date(); print "Before date span:" . PHP_EOL; print "event1 info: " . $date1->getDate() . "\t" . $date1->getTzId() . PHP_EOL; print "event2 info: " . $date2->getDate() . "\t" . $date2->getTzId() . PHP_EOL; $span = new Date_Span(); $span->setFromDateDiff($date1, $date2); print "After date span:" . PHP_EOL; print "event1 info: " . $date1->getDate() . "\t" . $date1->getTzId() . PHP_EOL; print "event2 info: " . $date2->getDate() . "\t" . $date2->getTzId() . PHP_EOL; ?>