You might want to take a look at this 2 snippets:
http://www.zfsnippets.com/snippets/view/id/39
http://www.zfsnippets.com/snippets/view/id/43
Regards,
Saša Stamenković.
Marko Korhonen wrote:
>
> Thanks Thomas,
>
> So I ended up with view helper "Duration".
>
> class My_View_Helper_Duration extends Zend_View_Helper_Abstract
> {
> /**
> * Get duration in minutes and seconds
> *
> * @param int $seconds Seconds
> * @return string Duration
> */
> public function duration($seconds)
> {
> $seconds = Zend_Filter::get($seconds, "Int");
>
> $date = new Zend_Date($seconds, Zend_Date::SECOND);
>
> return $this->view->translate("duration-%d-%d",
> $date->toString("mm"),
> $date->toString("ss"));
> }
> }
>
> Where I get string "4 min 12 s" for example.
>
>
> br, Marko
>
>
> thomasW wrote:
>>
>> Marko,
>>
>>> I list YouTube videos with Zend_Gdata_Youtube.
>>>
>>>>From youtube I get duration in seconds.
>>>
>>> I made conversion with Zend_Measure with following code:
>>>
>>> // example: duration 188s
>>> $input = new Zend_Measure_Time($videoEntry->getVideoDuration(),
>>> Zend_Measure_Time::SECOND);
>>>
>>> // example outputs 3.13min which is correct: 188/60=3.13
>>> echo $input->convertTo('MINUTE');
>>>
>>> BUT, should it make 3 min 8 s kinda string? Now I have no use for this
>>> conversion
>>> and I propably end up making view helper converting seconds to
>>> minutes+seconds.
>>>
>>> I just wanted to ask if anybody knows better way or something about
>>> Zend_Measure that I have missed.
>>
>> Zend_Measure handles measurements.
>>
>> First you have seconds, but what you expect is to get 2 measurements
>> returned.
>> Seconds and Minutes... from Zend_Measures point of view the returned
>> value
>> is correct.
>> You wanted to have minutes and written in minutes the result is a float.
>>
>> But you want to get a time value and not one measurement.
>> So, when you want to have date calculations then you should use
>> Zend_Date.
>>
>> In this case the simplest way is to call:
>>
>> $date = Zend_Date(188, Zend_Date:SECONDS);
>> $date->toArray();
>> or
>> $date->toString('mm.ss');
>>
>> Greetings
>> Thomas Weidner, I18N Team Leader, Zend Framework
>> http://www.thomasweidner.com
>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Zend_Measure-and-time-tp24167528p24182085.html
Sent from the Zend Framework mailing list archive at Nabble.com.