Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created November 2, 2015 08:14
Show Gist options
  • Select an option

  • Save dpaluy/2d6439e50939f5b37998 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/2d6439e50939f5b37998 to your computer and use it in GitHub Desktop.
Time to decimal convert
def time_to_decimal(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)
# Final value ready
(hours + minutes).round(2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment