ZF-8687: add day at last month return wrong year by 'Y' identifier

Issue Type: Bug Created: 2010-01-01T12:31:15.000+0000 Last Updated: 2010-01-01T13:05:19.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Jonas Martinez (muan) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: - ZF-5297



When i use Zend_Date to add 1 day and subtract 2 days for obtain next and previous day, it return wrong year.

Example: $date = new Zend_Date('2009-12-31');

$date->add(1, Zend_Date::DAY); //Expected 2010-01-01

echo $date; //Return 2010-01-01 00:00:00, its all right echo $date->get('Y'); //Return 2009, wrong year! echo $date->get(Zend_Date::YEAR); //Return 2010, right!

$date->sub(2, Zend_Date::DAY); //Expected 2009-12-30

echo $date; //Return 2009-12-30 00:00:00, its all right echo $date->get('Y'); //Return 2009, right! echo $date->get(Zend_Date::YEAR); //Return 2009, right!


Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-01-01T12:33:24.000+0000

Are you sure it's not related to this issue?

Posted by Jonas Martinez (muan) on 2010-01-01T12:59:06.000+0000

Yes Dolf, thanks!

Posted by Thomas Weidner (thomas) on 2010-01-01T13:02:18.000+0000

Closing as non-issue.

Please read the manual:…

{quote} Note that the default ISO format differs from PHP's format which can be irritating if you have not used in previous. Especially the format specifiers for Year and Minute are often not used in the intended way.

For year there are two specifiers available which are often mistaken. The Y specifier for the ISO year and the y specifier for the real year. The difference is small but significant. Y calculates the ISO year, which is often used for calendar formats. See for example the 31. December 2007. The real year is 2007, but it is the first day of the first week in the week 1 of the year 2008. So, if you are using 'dd.MM.yyyy' you will get '31.December.2007' but if you use 'dd.MM.YYYY' you will get '31.December.2008'. As you see this is no bug but a expected behaviour depending on the used specifiers.

For minute the difference is not so big. ISO uses the specifier m for the minute, unlike PHP which uses i. So if you are getting no minute in your format check if you have used the right specifier. {quote}

Or look into the FAQ where often made failures are mentioned:…

{quote} Why are my dates formatted wrong? Why do I get the false year value?

When using own formats in your code you could come to a situation where you get for example 29.12.2009, but you expected to get 29.12.2008.

There is one year difference: 2009 instead of 2008. You should use the lower cased year constant. See this example:

$date->toString('dd.MM.yyyy'); Note the lower cased "y" which makes the difference and outputs the real year. {quote}

Posted by Jonas Martinez (muan) on 2010-01-01T13:05:19.000+0000

thx, sorry the inconvenient, i try to search but i'm new on JIRA and dont found... (sry poor english)

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.