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

Request #3345 Add methode to Date_Span which returns a nice formatted Span array
Submitted: 2005-02-01 12:07 UTC
From: tacker Assigned: pajoye
Status: Wont fix Package: Date
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-02-01 12:07 UTC] tacker
Description: ------------ Add methode to Date_Span which returns a nice formatted Span array Reproduce code: --------------- --- Span.php 2005-02-01 12:59:50.205441280 +0100 +++ /usr/lib/php/Date/Span.php 2005-02-01 12:49:56.000000000 +0100 @@ -934,6 +921,40 @@ } /** + * Create an array with days, hours, minutes and seconds + * + * @return array + */ + function getNice() + { + $ret = array( + 'days' => 0, + 'hours' => 0, + 'minutes' => 0, + 'seconds' => 0, + ); + $seconds = $this->toSeconds(); + // Calculate the days + while ($seconds >= 86400) { + $ret['days']++; + $seconds -= 86400; + } + // Calculate the hours + while ($seconds >= 3600) { + $ret['hours']++; + $seconds -= 3600; + } + // Calculate the minutes + while ($seconds >= 60) { + $ret['minutes']++; + $seconds -= 60; + } + // Save the rest as seconds + $ret['seconds'] = $seconds; + return $ret; + } + + /** * Returns a copy of the object (workarround for PHP5 forward compatibility). * * @return object Date_Span Copy of the object.

Comments