Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created June 18, 2013 13:03
Show Gist options
  • Save natritmeyer/5805166 to your computer and use it in GitHub Desktop.
Save natritmeyer/5805166 to your computer and use it in GitHub Desktop.
Converts a float/active_support-time to print a duration (ie: a date time that starts from 0000 instead of the epoch, ie: 1/1/1970)
require 'active_support/time'
def duration_of(input)
Time.at(input).gmtime.strftime "0000-00-00T%H:%M:%S"
end
duration_of 6.seconds #=> "0000-00-00T00:00:06"
duration_of 70.seconds #=> "0000-00-00T00:01:10"
duration_of 5.minutes #=> "0000-00-00T00:05:00"
@natritmeyer
Copy link
Author

Thanks to @JamsAlx for the inspiration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment