Quantcast

Handling time measures

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

Handling time measures

Fernando
Hi,

I have a time measure ( originally in seconds ) and i want to convert it to HH:mm:ss format. Zend_Date does not seem like a good solution for me as i will eventually have times with more than 24 hours.

Zend_Measure_Time will convert to only one unit ( hours, minutes etc. ) but not in the format that i want.

My question is if there is a way do this without having to extend Zend_Measure_Time? Any other component that have this feature?

Thanks,

Fernando Morgenstern
[hidden email]





--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


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

Re: Handling time measures

David Muir
You mean something like:

function toHMS($time){
$seconds = $time % 60;
$minutes = (($time-$seconds) % 3600) / 60;
$hours   = (int) ($time-$minutes)/3600;
return sprintf('%02d:%02d:%02d',$hours , $minutes, $seconds);
}

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

Re: Handling time measures

Fernando
Yes, but i decided to first ask here in case i was missing some point.

I ended up extending Zend_Time_Measure yesterday with a new unit for time and something very close to what you suggested.

Thanks for your reply,

Fernando Morgenstern
[hidden email]




Em 13/04/2011, às 02:27, David Muir escreveu:

> You mean something like:
>
> function toHMS($time){
> $seconds = $time % 60;
> $minutes = (($time-$seconds) % 3600) / 60;
> $hours   = (int) ($time-$minutes)/3600;
> return sprintf('%02d:%02d:%02d',$hours , $minutes, $seconds);
> }
>
> Cheers,
> David
>
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/Handling-time-measures-tp3444772p3446310.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>


--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


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

AW: [fw-general] Handling time measures

Thomas Weidner
In reply to this post by Fernando
Hy,

use Zend_Measure_Time by suppressing values below 1.

$hours = $time->convert($input, Zend_Measure_Time::HOUR);
$input -= $hours*3600;
$minutes = $time->convert($input, Zend_Measure_Time::MINUTES);
$input -= $minutes * 60;
$seconds = $time->convert($input, Zend_Measure_Time::SECONDS);

print($hours . ':' . $minutes . ':' . $seconds);

Still for such an easy task I would do it manually.

Greetings
Thomas

-----Ursprüngliche Nachricht-----
Von: Fernando Marcelo [mailto:[hidden email]]
Gesendet: Dienstag, 12. April 2011 16:33
An: Zend Framework
Betreff: [fw-general] Handling time measures

Hi,

I have a time measure ( originally in seconds ) and i want to convert it to
HH:mm:ss format. Zend_Date does not seem like a good solution for me as i
will eventually have times with more than 24 hours.

Zend_Measure_Time will convert to only one unit ( hours, minutes etc. ) but
not in the format that i want.

My question is if there is a way do this without having to extend
Zend_Measure_Time? Any other component that have this feature?

Thanks,

Fernando Morgenstern
[hidden email]





--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]




--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Loading...