Created
January 19, 2013 08:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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