ZF-11992: Wrong date in Zend_Date

Issue Type: Bug Created: 2012-01-12T14:26:07.000+0000 Last Updated: 2013-03-13T20:55:21.000+0000 Status: Reopened Fix version(s): - Next Mini Release ()

Reporter: Volodymyr Labo (blessed) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Date

Related issues: - ZF-12507



I have the code: $days = 12 $today = new Zend_Date(date('Y-m-d'), 'YYYY-MM-dd'); $minusTwoWeeks = $today->subDay($days); echo date('Y-m-d', $minusTwoWeeks->toValue());

Today is 2012-01-12 So I receive 2011-12-31 And it is correct. If I change $days to 10, I receive 2012-01-02 and it is also correct. But if I change $days to 11 I receive 2011-01-02. The year is incorrect! I tried several times, the result was the same. Then I waited 15 minutes, after that everything became good. 2012-01-01. But why it has changed?


Posted by Adam Lundrigan (adamlundrigan) on 2012-02-26T05:22:35.000+0000

Can you provide an exact date/time (down to the second) at which is error occurs? As you said it didn't recur when you tried again later, we'll need more than just the Ymd to dig deeper.

Posted by Rafael Kassner (kassner) on 2012-03-20T21:14:29.000+0000

Just adding some example code that showing the problem

This problem appears only when we use the 1st day of the year.

It happens in 1.11.11 and 1.9.6 (don't bother, it was a old Magento Install).

Posted by Matthew Weier O'Phinney (matthew) on 2012-06-12T20:56:17.000+0000

Fixed in trunk with r24880; will release with 1.12.0.

Basically, Zend_Date converts all formats to ISO 8601 standards. This means that "o" is used for the year instead of "Y". If you look at you'll see an interesting note for "o" -- when the day of the week falls within the last week of the previous year, "o" will evaluate to the previous year. As such, I've added a regex that will replace "o" with "Y" when not preceded by an escape, thus giving us the desired behavior.

Posted by Peter Moolenaar (pmoolenaar) on 2013-01-12T15:42:49.000+0000

Uhm, however that was expected behaviour! See the note just before…

I've been looking all over for this 'suddenly' altered behaviour. I'm sticking with the manual that states that using uppercase Y's will return me the week-based ISO year.

Posted by Peter Moolenaar (pmoolenaar) on 2013-01-17T11:14:27.000+0000

And, I'll add another comment to this one. I'd opened a new bug for this, however that got closed with the remark that the original one should be reopend. So, please do so. This implementation actually breaks my applications and it actually degrades my opinion of the stability of ZF since it doesn't even conform to its own manual anymore!

Posted by Frank Brückner (frosch) on 2013-01-17T11:32:27.000+0000

@Peter Can you help me and provide some examples which I can use for unit test? That would be great. I am very busy, because I work on the next release (1.12.2) and also on the ZF website.

Thanks in advance.

Posted by Peter Moolenaar (pmoolenaar) on 2013-01-17T11:48:09.000+0000

Sure, the test is quite simple (adhering to the manual that is :)). {quote} $date = new Zend_Date('2012-12-31'); echo $date->toString('c'); // ISO conforming string: 2012-12-31T00:00:00+01:00 (I'm in Europe/Amsterdam tz) $calendarYear = $date->get(Zend_Date::YEAR); // Expect 2012 $isoBasedYear = $date->get(Zend_Date::YEAR_8601); // Expect 2013 echo '
'.$calendarYear.' vs. '.$isoBasedYear; {quote} The original mentioned problem is the other way around (the first day of 2012 (2012-01-01) falls in the last week of the previous year and should render '2012 vs. 2011'). However it is simply a misinterpretation of how the different tokens work. In the more elaborate example from pastebin he actually tests both uppercase and lowercase y and deduces that, without argumentation, they should actually be the same (with which I obviously disagree :)).

Have you found an issue?

See the Overview section for more details.


© 2006-2020 by Zend by Perforce. Made with by awesome contributors.

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