Issues

ZF-8332: Zend_Date fails on 31 of month

Issue Type: Bug Created: 2009-11-18T22:36:36.000+0000 Last Updated: 2009-11-19T08:52:36.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Daniel Guerrero (danguer) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: Attachments:

Description

I've tested on two servers both with Zend Framework 1.9 and PHP 5.2.6 the following code:


$date = new Zend_Date(); $date->setDay(31); $date->setMonth(5); $date->setYear(2009);

print "DATE: ".date('d/m/Y', $date->getTimestamp());

Outputs: DATE: 01/05/2009

Expected Output: DATE: 31/05/2009

If you put any valid month that have 31 days you will always get 01 as day in the same month.

Comments

Posted by Thomas Weidner (thomas) on 2009-11-19T02:17:28.000+0000

No problem at all. You are just doing things wrong.

Example:

<pre class="highlight">
$date = new Zend_Date();

19.Nov.2009 is set

<pre class="highlight">
$date->setDay(31);

1.Dec.2009 is set Because there is no 31.Nov. So the valid date is used.

<pre class="highlight">
$date->setMonth(5);

1.May.2009 is set

<pre class="highlight">
$date->setYear(2009);

1.May.2009 is set

When working with dates you need eighter to set a date at once, or by setting from highest to lowest value. From Year, to Month, to Day, and not reverse.

You could also set the extend_months option. But this could add other problems when you are not aware of what you are doing.

Posted by Thomas Weidner (thomas) on 2009-11-19T02:18:06.000+0000

Closing as non-issue Wrong usage.

Posted by Daniel Guerrero (danguer) on 2009-11-19T08:52:35.000+0000

Thanks for the clarification, I forgot that date is calculated on each call (I thought that calculation was done on call of getTimestamp())

Regards,

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts