ZF-2873: Setting date with array gives wrong result




include ('Zend/Date.php');

$date = new Zend_Date();
    '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.


include ('Zend/Date.php');

$date = new Zend_Date();
$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



include ('Zend/Date.php');

$date = new Zend_Date();
echo $date->get(Zend_Date::ISO_8601);

Result: 2008-05-29T23:59:59+02:00


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.

  1. Can you tell me what is the difference between the other two methods.
  2. Is it possible to create a date ,with an array, that gives me the result: 2008-05-29T23:59:59+02:00

An example: I will calculate a membership time. This membership time shall expire at 2008-05-29T23:59:59 at german time.

  1. You are using different constants. Which you should use depends on your input.
  2. Yes

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

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.

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:

require_once 'Zend/Date.php';

$date = new Zend_Date();
$date->set(array('year' => 2008, 'month' => 5, 'day' => 29));
$date->setTime(array('hour' => 23, 'minute' => 59, 'second' => 59));

echo $date->getIso();