Converting Seconds to Timeclock Display
By chris on March 14th 2007 in /dev/rails, /dev/ruby | 500 views
This seems like functionality that should already be built into a Ruby class (Time?) or a Rails helper but I couldn't find it. This simply converts a chunk of seconds into hh:mm:ss display:
RUBY:
-
time_str = [ seconds / 3600, seconds / 60 % 60, seconds % 60].map { |t| t.to_s.rjust( 2, '0' ) }.join( ':' )
which outputs 02:44:13.
What I'm really looking for is a conversion from seconds into the likes of
1 day, 8 hours, 44 minutes, 11 seconds
similar to what the Rails DateHelper does with distance_of_time_in_words. If you know of such a thing, please point me to it.
