Issues

ZF-5297: READ FIRST: Incorrect year returned by Zend_Date.

Description

Dear Sir/Madam,

Recently a lot of ZF users are filing a bug that Zend_Date returns the wrong year, 2009 instead of 2008. This is however expected behaviour, and NOT A BUG!

From the FAQ:

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'); instead of

$date->toString('dd.MM.YYYY');

From the manual

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.

Please leave this issue open at least until January 2009.

Comments

I think one of the reasons this confuses so many people is a misinterpretation of the ISO spec. The manual claims 'ISO uses weeknumberbasedyear, so 1-1-2010 is actually 2009 according to ISO, so it's intended behaviour'.

ISO would cease to exist if it could rightfully claim that 1-1-2010 is actually in 2009.

ISO has 2 ways of representing the year number:

1-1-2009 according to ISO 8601 Calendrial year: 2009 1-1-2009 according to ISO 8601 Weeknumberbased year: 2008

The first one is the most commonly used and the one to be used in full date representations. Zend_Date wrongfully ignores the first one and claims the second one is the only 'iso correct date'. This is wrong and causes confusion to people who use the common YYYY representation in their formatting. In my opinion, it IS a bug, and YYYY should use the ISO 8601 calendrial year representation. This means it will correctly represent 1-1-9 as '2009', and still be ISO compliant. The less common weeknumber based representation could then use a less obvious formatting string.

Clearly, there is (a) confusion by many, many users of the component, and (b) confusion as to implementation of the specification. Zend_Date usage should be predictable, and if it is not, should be fixed.

PHP's DateTime is how people expect Zend_Date to act. If it does not, it should be corrected.

It should. But, if we were to change this (no matter in a major, minor or mini release) it would break a lot of sites, without people knowing. With other BC breaks you get an exception, notice, etc. However, that would be not really possible with any change we're discussing here.

Dolf: I think that's ok, I doubt many people are actually using the weeknumber based year; there are hardly any use case scenario's that need this particular weird year.

Most of the people currently using it will not notice a change, in fact it might fix a problem they didn't yet know they had.

Issue postponed for 2.0