ZF-10584: Zend_Date::setTime doesn't check if dst change

Description

calling method Zend_Date::setTime("08:00:00") on date "2010-10-31 00:00:00" results with date "2010-10-31 07:00:00". This is because of dst change.

Comments

I'm having this same problem. I'm in timezone "Australia/Melbourne"

Daylight savings finished on 3-Apr-2011 and so we lost the hour between 2am-3am on that day.

This code triggers the problem for me:


date_default_timezone_set('Australia/Melbourne');

$date = new Zend_Date('03-Apr-2011', 'dd/MMM/yyyy');
$date->setHour(6);

echo $date->getIso();

//2011-04-03T05:00:00+10:00a:1301749200

I think the priority should be bumped up. A bug like this in setHour/setTime means you can't really use the function for a lot of things.

Sorry, I mean we gained an hour that day.

I just spent several hours tracking this down in my calendar application.


date_default_timezone_set('America/New_York');

echo '
';

$a = new Zend_Date('2012-03-11 00:00:00', 'yyyy-MM-dd HH:mm:ss');
$a->setTime('04:00:00', 'HH:mm:ss');
echo $a->toString('yyyy-MM-dd HH:mm:ss', 'iso') . ' // expected: 2012-03-11 04:00:00' . PHP_EOL;

$b = new Zend_Date('2012-03-11 04:00:00', 'yyyy-MM-dd HH:mm:ss');
$b->setTime('00:00:00', 'HH:mm:ss');
echo $b->toString('yyyy-MM-dd HH:mm:ss', 'iso') . ' // expected: 2012-03-11 00:00:00' . PHP_EOL;

$c = new Zend_Date('2012-11-04 00:00:00', 'yyyy-MM-dd HH:mm:ss');
$c->setTime('04:00:00', 'HH:mm:ss');
echo $c->toString('yyyy-MM-dd HH:mm:ss', 'iso') . ' // expected: 2012-11-06 04:00:00' . PHP_EOL;

$d = new Zend_Date('2012-11-04 04:00:00', 'yyyy-MM-dd HH:mm:ss');
$d->setTime('00:00:00', 'HH:mm:ss');
echo $d->toString('yyyy-MM-dd HH:mm:ss', 'iso') . ' // expected: 2012-11-06 00:00:00' . PHP_EOL;

echo '
';
2012-03-11 05:00:00 // expected: 2012-03-11 04:00:00
2012-03-10 23:00:00 // expected: 2012-03-11 00:00:00
2012-11-04 03:00:00 // expected: 2012-11-06 04:00:00
2012-11-04 01:00:00 // expected: 2012-11-06 00:00:00

Why is this marked as minor? I'm not sure how to work around it.

I posted on Stack Overflow, and have a work around for now. It's far from optimal. This really needs to be fixed. http://stackoverflow.com/questions/7181702/…

Upvoted. It would be really nice to have a fix for this.