Zend date add/sub methods don't change year ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Zend date add/sub methods don't change year ?

debussy007
Hello,

When I add a second to '2010-12-31 23:59:59', I get '2010-01-01 00:00:00'. Instead of 2011 I have 2010

Test code :

$t = '2010-12-31 23:59:59';
$zd = new Zend_Date($t, 'YYYY-MM-dd HH:mm:ss');
echo $zd->get('YYYY-MM-dd HH:mm:ss');
echo '<br>';
$zd->addSecond(1);
echo $zd->get('YYYY-MM-dd HH:mm:ss');
echo '<br>';

Prints :

2010-12-31 23:59:59
2010-01-01 00:00:00
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

AW: [fw-general] Zend date add/sub methods don't change year ?

Thomas Weidner
Look into the FAQ and the manual what the difference between "Y" and "y" is.

Best regards,
Thomas Weidner

Zend Framework Certified Engineer & I18N Team Leader
http://www.thomasweidner.com

-----Ursprüngliche Nachricht-----
Von: debussy007 [mailto:[hidden email]]
Gesendet: Samstag, 18. September 2010 12:17
An: [hidden email]
Betreff: [fw-general] Zend date add/sub methods don't change year ?


Hello,

When I add a second to '2010-12-31 23:59:59', I get '2010-01-01 00:00:00'.
Instead of 2011 I have 2010

Test code :

$t = '2010-12-31 23:59:59';
$zd = new Zend_Date($t, 'YYYY-MM-dd HH:mm:ss'); echo $zd->get('YYYY-MM-dd
HH:mm:ss'); echo '<br>'; $zd->addSecond(1); echo $zd->get('YYYY-MM-dd
HH:mm:ss'); echo '<br>';

Prints :

2010-12-31 23:59:59
2010-01-01 00:00:00
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-date-add-sub-metho
ds-don-t-change-year-tp2544881p2544881.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Zend date add/sub methods don't change year ?

till-2
In reply to this post by debussy007
On Sat, Sep 18, 2010 at 12:17 PM, debussy007 <[hidden email]> wrote:

>
> Hello,
>
> When I add a second to '2010-12-31 23:59:59', I get '2010-01-01 00:00:00'.
> Instead of 2011 I have 2010
>
> Test code :
>
> $t = '2010-12-31 23:59:59';
> $zd = new Zend_Date($t, 'YYYY-MM-dd HH:mm:ss');
> echo $zd->get('YYYY-MM-dd HH:mm:ss');
> echo '<br>';
> $zd->addSecond(1);
> echo $zd->get('YYYY-MM-dd HH:mm:ss');
> echo '<br>';

To elaborate - YYYY is incorrect in this case. You're assuming that
Zend_Date uses PHP's format by default but it does not. It uses the
ISO format by default.

Prepend this to your code:
Zend_Date::setOptions(array('format_type' => 'php'));

Till
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Zend date add/sub methods don't change year ?

jasonistaken
On 18/09/2010 9:51 AM, till wrote:

> On Sat, Sep 18, 2010 at 12:17 PM, debussy007<[hidden email]>  wrote:
>>
>> Hello,
>>
>> When I add a second to '2010-12-31 23:59:59', I get '2010-01-01 00:00:00'.
>> Instead of 2011 I have 2010
>>
>> Test code :
>>
>> $t = '2010-12-31 23:59:59';
>> $zd = new Zend_Date($t, 'YYYY-MM-dd HH:mm:ss');
>> echo $zd->get('YYYY-MM-dd HH:mm:ss');
>> echo '<br>';
>> $zd->addSecond(1);
>> echo $zd->get('YYYY-MM-dd HH:mm:ss');
>> echo '<br>';
>
> To elaborate - YYYY is incorrect in this case. You're assuming that
> Zend_Date uses PHP's format by default but it does not. It uses the
> ISO format by default.
>
> Prepend this to your code:
> Zend_Date::setOptions(array('format_type' =>  'php'));
>
> Till

That won't fix it. He's using ISO formatting codes, just using them kinda incorrectly.
Loading...