Skip to content

Instantly share code, notes, and snippets.

@thanashyam
Created January 19, 2013 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thanashyam/4571386 to your computer and use it in GitHub Desktop.
Save thanashyam/4571386 to your computer and use it in GitHub Desktop.
*Time Conversion Helper Methods*: Converting seconds into HH::MM format Converting Time in HH:MM format or in decimal format into seconds
#Converting seconds into HH::MM format
def get_time_in_hours seconds
Time.at(seconds).utc.strftime("%H:%M")
end
#Converting Time in HH:MM format or in decimal format into seconds
def convert_duration(duration)
if duration =~ /^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
time_pieces = duration.split(":")
hours = time_pieces[0].to_i
minutes = (time_pieces[1].to_f/60.0)
duration = hours + minutes
end
(duration.to_f * 60 * 60).to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment