ZF-2873: Setting date with array gives wrong result
Description
Code
date_default_timezone_set('UTC');
include ('Zend/Date.php');
$date = new Zend_Date();
$date->setTimezone('Europe/Berlin');
$date->set(array(
'year' => 2008,
'month' => 5,
'day' => 29,
'hour' => 23,
'minute' => 59,
'second' => 59
));
echo $date->get(Zend_Date::ISO_8601);
Expected result: 2008-05-29T23:59:59+02:00
Actual result: 2008-05-30T00:59:59+02:00
When i set the date individually over the Zend_Date->set() method with the constants. It works correct.
date_default_timezone_set('UTC');
include ('Zend/Date.php');
$date = new Zend_Date();
$date->setTimezone('Europe/Berlin');
$date->set(2008, Zend_Date::YEAR);
$date->set(5, Zend_Date::MONTH);
$date->set(29, Zend_Date::DAY);
$date->set(23, Zend_Date::HOUR);
$date->set(59, Zend_Date::MINUTE);
$date->set(59, Zend_Date::SECOND);
echo $date->get(Zend_Date::ISO_8601);
Result: 2008-05-29T23:59:59+02:00
or
date_default_timezone_set('UTC');
include ('Zend/Date.php');
$date = new Zend_Date();
$date->setTimezone('Europe/Berlin');
$date->set('29.05.2008',Zend_Date::DATES);
$date->set('23:59:59',Zend_Date::TIMES);
echo $date->get(Zend_Date::ISO_8601);
Result: 2008-05-29T23:59:59+02:00
Comments
Posted by Thomas Weidner (thomas) on 2008-03-13T05:31:47.000+0000
No, this is not an issue...
You defined to use the actual time... we now have wintertime. Then you said to set the date 29.05.2008... this date is in summertime... so you have a gap of one hour in the date object from the actual date and the new date. As you define your new time in the old date (you set the complete array) the gap of one hour is added as result to the change of being in summertime.
When you rely on UTC you will not have any gap because UTC does not have a summer/wintertime.
This issue is (partitially) identical with ZF-2587.
Posted by Christian Kaps (akkie) on 2008-03-13T06:46:30.000+0000
An example: I will calculate a membership time. This membership time shall expire at 2008-05-29T23:59:59 at german time.
Posted by Thomas Weidner (thomas) on 2008-03-14T02:09:19.000+0000
Posted by Christian Kaps (akkie) on 2008-03-14T03:27:17.000+0000
O sorry my english is not the best. That what i mean for point 1 is what is the difference between the first example and the other two examples. Can you give me an example for point two?
What is the best method to create a date in a timezone they differs from the main time zone which was set by the date_default_timezone_set() function?
Best regards
Posted by Wil Sinclair (wil) on 2008-03-21T17:34:14.000+0000
I'm assuming this fix is merged to the 1.5 release branch for release with 1.5.1. Please update JIRA if this is not the case.
Posted by Thomas Weidner (thomas) on 2008-03-24T14:21:07.000+0000
The constant DATES is different depending on the used locale. The format it produces is for example "dd.MM.yyyy" or "MM/dd/yyyy"...
Your second example uses fixed constants which are not different depending on the locale. That's what I meant with "you are using different constants".
We do not code anything for people... see this as exception to this rule: