Details
-
Type:
Bug
-
Status:
Postponed
-
Priority:
N/A
-
Resolution: Unresolved
-
Affects Version/s: 1.7.1
-
Fix Version/s: None
-
Component/s: Zend_Date
-
Labels:None
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.
Issue Links
| This issue is duplicated by: | ||||
| ZF-7474 | Subsequent subtracting/addition actions on Zend_Date at end of year |
|
|
|
| ZF-5296 | Zend_Date returns wrong year for 2008-12-29 till 2008-12-31 |
|
|
|
| ZF-4656 | toString('YYYY-MM-dd') sends us in the future... |
|
|
|
| ZF-3724 | inconsistent results |
|
|
|
| ZF-5281 | Date conversion error ->toString('YYYY') |
|
|
|
| ZF-5120 | Zend_Date->toString YYYY bug(?) |
|
|
|
| ZF-4820 | Zend_date 12 december 2009 to januari 2010 problem |
|
|
|
| ZF-5371 | Date output format bug |
|
|
|
| ZF-5719 | Zend Date bug with years |
|
|
|
| ZF-5723 | Zend_Date outputs wrong year |
|
|
|
| ZF-8703 | Zend_Date misses 3 days of a new year starting from 2010 |
|
|
|
| ZF-8687 | add day at last month return wrong year by 'Y' identifier |
|
|
|
| This issue is related to: | ||||
| ZF-10776 | Zend_XmlRpc_Value_DateTime uses wrong ISO format string |
|
|
|
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.