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

Description

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!

Comments

Are you sure it's not related to this issue? http://framework.zend.com/issues/browse/ZF-5297

Yes Dolf, thanks!

Closing as non-issue.

Please read the manual: http://framework.zend.com/manual/en/…

{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: http://framework.zend.com/wiki/display/…

{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}

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