Problem of Zend_Date::addDay

3 messages Options
Embed this post
Permalink
Jace Ju

Problem of Zend_Date::addDay

Reply Threaded More More options
Print post
Permalink
Hi All:

I found a problem of Zend_Date:

[code]
<?php
require_once 'Zend/Date.php';

date_default_timezone_set('Asia/Taipei');

$today = new Zend_Date();
$today->setDate('2008-11-21');

$expireDateTime = clone $today;
$expireDateTime->addDay(40);

echo $expireDateTime->toString('YYYY-MM-dd');

// expect : 2008-12-31
// actual : 2009-12-31
[/code]

When I used addDay method to add $today to year 2001~2008, month 12, and day 29~31, the year would be wrong.

For Example:

2008-11-09 + 50(days) = 2009-12-29 (wrong)
2008-11-01 + 50(days) = 2008-12-21 (right)
2007-11-21 + 40(days) = 2008-12-31 (wrong)
2007-11-11 + 50(days) = 2008-12-31 (wrong)
2009-11-11 + 50(days) = 2009-12-31 (right)
2009-11-21 + 40(days) = 2008-12-31 (right)
2000-11-21 + 40(days) = 2000-12-31 (right)
2001-11-21 + 40(days) = 2002-12-31 (wrong)
...

Is this a bug? Or missing out something?

Please forget my poor english.



Jace Ju
thomasW

Re: Problem of Zend_Date::addDay

Reply Threaded More More options
Print post
Permalink
Please read the manual or the API.
The format string "Y" is not the real year.
ISO defines it as calendar year (or year of the week) which is calculated
differently.

Use "y" when you need the real year.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Jace Ju" <[hidden email]>
To: <[hidden email]>
Sent: Friday, November 14, 2008 10:33 AM
Subject: [fw-core] Problem of Zend_Date::addDay


> Hi All:
>
> I found a problem of Zend_Date:
>
> [code]
> <?php
> require_once 'Zend/Date.php';
>
> date_default_timezone_set('Asia/Taipei');
>
> $today = new Zend_Date();
> $today->setDate('2008-11-21');
>
> $expireDateTime = clone $today;
> $expireDateTime->addDay(40);
>
> echo $expireDateTime->toString('YYYY-MM-dd');
>
> // expect : 2008-12-31
> // actual : 2009-12-31
> [/code]
>
> When I used addDay method to add $today to year 2001~2008, month 12, and
> day
> 29~31, the year would be wrong.
>
> For Example:
>
> 2008-11-09 + 50(days) = 2009-12-29 (wrong)
> 2008-11-01 + 50(days) = 2008-12-21 (right)
> 2007-11-21 + 40(days) = 2008-12-31 (wrong)
> 2007-11-11 + 50(days) = 2008-12-31 (wrong)
> 2009-11-11 + 50(days) = 2009-12-31 (right)
> 2009-11-21 + 40(days) = 2008-12-31 (right)
> 2000-11-21 + 40(days) = 2000-12-31 (right)
> 2001-11-21 + 40(days) = 2002-12-31 (wrong)
> ...
>
> Is this a bug? Or missing out something?
>
> Please forget my poor english.
>
>
>
> Jace Ju
>

Jace Ju-2

Re: Problem of Zend_Date::addDay

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hi Thomas:

This is my fault. Thank you.

2008/11/14, Thomas Weidner <[hidden email]>:
Please read the manual or the API.
The format string "Y" is not the real year.
ISO defines it as calendar year (or year of the week) which is calculated differently.

Use "y" when you need the real year.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Jace Ju" <[hidden email]>
To: <[hidden email]>
Sent: Friday, November 14, 2008 10:33 AM
Subject: [fw-core] Problem of Zend_Date::addDay



Hi All:

I found a problem of Zend_Date:

[code]
<?php
require_once 'Zend/Date.php';

date_default_timezone_set('Asia/Taipei');

$today = new Zend_Date();
$today->setDate('2008-11-21');

$expireDateTime = clone $today;
$expireDateTime->addDay(40);

echo $expireDateTime->toString('YYYY-MM-dd');

// expect : 2008-12-31
// actual : 2009-12-31
[/code]

When I used addDay method to add $today to year 2001~2008, month 12, and day
29~31, the year would be wrong.

For Example:

2008-11-09 + 50(days) = 2009-12-29 (wrong)
2008-11-01 + 50(days) = 2008-12-21 (right)
2007-11-21 + 40(days) = 2008-12-31 (wrong)
2007-11-11 + 50(days) = 2008-12-31 (wrong)
2009-11-11 + 50(days) = 2009-12-31 (right)
2009-11-21 + 40(days) = 2008-12-31 (right)
2000-11-21 + 40(days) = 2000-12-31 (right)
2001-11-21 + 40(days) = 2002-12-31 (wrong)
...

Is this a bug? Or missing out something?

Please forget my poor english.



Jace Ju