ZF-2873: Setting date with array gives wrong result

Issue Type: Bug Created: 2008-03-13T04:23:02.000+0000 Last Updated: 2008-03-24T14:21:07.000+0000 Status: Resolved Fix version(s): - 1.5.1 (25/Mar/08)

Reporter: Christian Kaps (akkie) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: Attachments:



<pre class="highlight">

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.

<pre class="highlight">

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


<pre class="highlight">

include ('Zend/Date.php');

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

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


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

  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.

Posted by Thomas Weidner (thomas) on 2008-03-14T02:09:19.000+0000

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

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:

<pre class="highlight">
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();

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.