Zend_Date: Incorrect results on the day the DST changes

β€œMarch 25, 2012” was the date when the time was changed from 02:00 to 03:00 in the Czech Republic. On this day, one function on my website stopped working correctly, and the client complained, etc. After digging a few hours, I realized that Zend_Date was behaving strangely that day:

#!/usr/bin/env php <?php include 'Zend/Date.php'; date_default_timezone_set('Europe/Prague'); shell_exec('sudo date --set="25 Mar 2012 12:00:00"'); $date = new Zend_Date(); $date->set('00:01:00', Zend_Date::TIMES); $startDate = $date->get(Zend_Date::TIMESTAMP); echo 'start date: ' . date("jnY H:i", $startDate) . PHP_EOL; $date->set('23:59:00', Zend_Date::TIMES); $endDate = $date->get(Zend_Date::TIMESTAMP); echo 'end date: ' . date("jnY H:i", $endDate) . PHP_EOL; 

It is output:

 start date: 24.3.2012 23:01 end date: 24.3.2012 23:59 

which is off during the day.

If I change the date to "March 26, 2012 12:00:00", it will correctly output:

 start date: 26.3.2012 00:01 end date: 26.3.2012 23:59 

Using mktime instead of Zend_Date works correctly in both cases. Is this a bug in Zend_Date? I think this is the case, so I already posted a bug report http://framework.zend.com/issues/browse/ZF-12121 . But maybe I am missing something obvious?

+4
source share
2 answers

I just found this when the stack overflowed, it fixed my problem perfectly (same as yours)

See Error in Zend_Date (back in time)

Good luck.

+1
source

When testing $date = new Zend_Date('2012-03-25 4:00:00', 'YYYY-MM-dd H:mm:ss'); code, date: $date = new Zend_Date('2012-03-25 4:00:00', 'YYYY-MM-dd H:mm:ss'); the result will be ok. Try to find out if the date output is the same when using $date->toString('dMyyyy HH:mm');

0
source

Source: https://habr.com/ru/post/1403654/


All Articles