Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.5.0a4

Bug #335 Date::addSeconds() adds hours instead of seconds
Submitted: 2003-12-02 02:31 UTC
From: aashley at optimiser dot com Assigned: pajoye
Status: Closed Package: Date
PHP Version: 4.3.3 OS: Gentoo Linux
Roadmaps: (Not assigned)    
Subscription  


 [2003-12-02 02:31 UTC] aashley at optimiser dot com
Description: ------------ Date::addSeconds() incorrectly calls the creation of the of the Date_Span object so that the Span assumes that the number specified is in hours not seconds. Patch to fix code: --- /home/aashley/pear/Date/Date.php 2003-11-18 10:21:44.000000000 +0800 +++ /usr/share/pear/Date.php 2003-12-02 10:25:12.097214200 +0800 @@ -576,7 +576,7 @@ */ function addSeconds($sec) { - $this->addSpan(new Date_Span($sec)); + $this->addSpan(new Date_Span('00:00:'.$sec)); } /** Reproduce code: --------------- <?php $date = new Date('2003-01-01 00:00:00'); $date->addSeconds(10); print $date->getDate(); ?> Expected result: ---------------- 2003-01-01 00:00:10 Actual result: -------------- 2003-01-01 10:00:00

Comments

 [2003-12-03 21:32 UTC] baba at php dot net
Thank you for taking the time to write to us, but this is not a bug. reproduce code produces expected result for me. Date_Span code treates integer only paramater as seconds. please check against 1.4rc1 package and comment if you can still produce this error.
 [2003-12-04 02:11 UTC] aashley at optimiser dot com
Okay further investigation and I narrowed down the problem. The seconds value I was adding was being retireved from a database so was being passed to addSeconds as a string, which cases setFromString to be called which interperates the value as hours. The following code demonstrates this: <?php include_once 'Date.php'; $date = new Date('2003-12-01 03:09:16'); $date->addSeconds('10'); print 'Add 10 seconds as a string: '.$date->getDate()."\n"; $date = new Date('2003-12-01 03:09:16'); $date->addSeconds(10); print 'Add 10 seconds as an integer: '.$date->getDate()."\n"; ?> Patch to fix: --- /home/aashley/pear/Date/Date.php 2003-12-04 10:11:51.978938200 +0800 +++ /usr/share/pear/Date.php 2003-12-04 10:10:34.500899754 +0800 @@ -582,7 +582,7 @@ */ function addSeconds($sec) { - $this->addSpan(new Date_Span($sec)); + $this->addSpan(new Date_Span((integer)$sec)); } /**
 [2003-12-15 08:04 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2003-12-15 08:22 UTC] aashley at optimiser dot com
if thats your intended behaviour for the function why have it at all? its just works as an alias for addSpan(). the fix I did was to make it behave as the name of the function implies its doing, adding this value as seconds.
 [2003-12-15 08:32 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!