ruby on rails - Show duration (in minutes) to hours -


i want display duration of movie. right movie.duration shown in minutes (integer)

%b duration: #{ @movie.duration } # 134 mins 

does rails have time helper show in more human-readable way? this:

duration: 2h 23min 

distance_of_time_in_words might you

docs: http://api.rubyonrails.org/classes/actionview/helpers/datehelper.html#method-i-distance_of_time_in_words

you can use this:

distance_of_time_in_words(0, 143*60) # "about 2 hours" <- result 

you need *60 because count in seconds, way count in minutes.

edit: can more rails way so:

distance_of_time_in_words(0, 143.minutes) 

you can calculate this:

"#{@movie.duration/60}h #{@movie.duration % 60}min" 

the division give hours while modulo give minutes


and if want more said, can use code here:

https://gist.github.com/csanz/669588


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -