Zend Framework

Zend_Date

the Year specifier problem

According to ZF's 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. 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.

so

date_default_timezone_set('GMT');
include 'vendor/autoload.php';
$a = new Zend_Date('2007-12-31');
echo $a->get('YYYY y');

should output 2008 2007

also see Stackoverflow discussion

but someone see this as a bug, so they fixed it, see ZF-11992: Wrong date in Zend_Date, the fix is incorporated in ZF 1.12, so with this version of ZF, Y is treated as y in PHP, you can only use the ISO meaning of Y by adding a backslash before it

date_default_timezone_set('GMT');
include 'vendor/autoload.php';
$a = new Zend_Date('2007-12-31', Zend_date::ISO_8601);

echo $a->get('Y y \Y');
// 2007 2007 \2008