Zend Framework

Zend_Date::addDay() does not work correctly on year changes

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.9.5
  • Fix Version/s: 1.9.6
  • Component/s: Zend_Date
  • Labels:
    None

Description

Sample code to reproduce:

$START_DATE = new Zend_Date('25.12.2009', 'dd.MM.YYYY');
$END_DATE   = new Zend_Date('15.01.2010', 'dd.MM.YYYY');
$cursor     = new Zend_Date($START_DATE);

while ($cursor->isEarlier($END_DATE)) {
    printf("%s<br/>", $cursor->toString('dd.MM.YYYY'));
    $cursor->addDay(7);
}

Expected output:

25.12.2009
01.01.2010
08.01.2010

Actual output:

25.12.2009
01.01.2009  // <--
08.01.2010

Activity

Hide
Raphael Pigulla added a comment -

Actually, further testing has shown that this is not a bug in addDay():

$timestamp = mktime(0, 0, 0, 1, 1, 2010);
$zend_date = new Zend_Date($timestamp, Zend_Date::TIMESTAMP);
printf("%s -- %s", strftime('%D', $timestamp), $zend_date->toString('MM/dd/YYYY'));

Output is:

01/01/10 -- 01/01/2009
Show
Raphael Pigulla added a comment - Actually, further testing has shown that this is not a bug in addDay():
$timestamp = mktime(0, 0, 0, 1, 1, 2010);
$zend_date = new Zend_Date($timestamp, Zend_Date::TIMESTAMP);
printf("%s -- %s", strftime('%D', $timestamp), $zend_date->toString('MM/dd/YYYY'));
Output is:
01/01/10 -- 01/01/2009
Hide
Christian Ehmig added a comment -

This bug seems to occur in ISO 8601 (year notation in capitals "Y") syntax only:

printf("%s -- %s", strftime('%D', $timestamp), $zend_date->toString('MM/dd/yyyy'));

produces the correct output:

01/01/10 -- 01/01/2010
Show
Christian Ehmig added a comment - This bug seems to occur in ISO 8601 (year notation in capitals "Y") syntax only:
printf("%s -- %s", strftime('%D', $timestamp), $zend_date->toString('MM/dd/yyyy'));
produces the correct output:
01/01/10 -- 01/01/2010
Hide
Thomas Weidner added a comment -

Please read the manual:

Note
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.

Show
Thomas Weidner added a comment - Please read the manual:
Note 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.
Hide
Thomas Weidner added a comment -

Closing as non-issue

Show
Thomas Weidner added a comment - Closing as non-issue

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: