4

"25 Mar 2012" was the date when time was changed from 02:00am to 03:00am in the Czech Republic. On that date, one functionality on my website stopped working correctly and a customer complained, etc. After digging for a few hours, I figured out that on that day Zend_Date behaved strangely:

#!/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("j.n.Y H:i", $startDate) . PHP_EOL;

$date->set('23:59:00', Zend_Date::TIMES);
$endDate = $date->get(Zend_Date::TIMESTAMP);
echo 'end date: ' . date("j.n.Y H:i", $endDate) . PHP_EOL;

This outputs:

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

which is off by day.

If I change the date to "26 Mar 2012 12:00:00", it correctly outputs:

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 it bug in Zend_Date? I think it is, so I have already posted a bug report http://framework.zend.com/issues/browse/ZF-12121. But maybe I am missing something obvious?

clime
  • 8,695
  • 10
  • 61
  • 82

2 Answers2

1

I've just find this on stack overflow, it perfectly fixed my issue (same as yours)

See Bug in Zend_Date (back in time)

Good luck

Community
  • 1
  • 1
supernaturall
  • 58
  • 1
  • 8
0

When testing the code with just hardcoding the date: $date = new Zend_Date('2012-03-25 4:00:00', 'YYYY-MM-dd H:mm:ss'); the result is ok. Try to see whether the date output is the same when using $date->toString('d.M.yyyy HH:mm');

Pieter
  • 1,764
  • 1
  • 12
  • 16
  • Only thing I can think of is that your system's timezone is not Europe/Prague, in which case PHP will recalculate the date/time based on the difference between Europe/Prague and your systems timezone. This is of course easily testable by doing `echo date('j.n.Y H:i');`Though, I am definitely not an expert so it might just as well be a bug in Zend_Date (it's a beast of a component after all). – Pieter May 11 '12 at 17:35