Created
November 2, 2015 08:14
-
-
Save dpaluy/2d6439e50939f5b37998 to your computer and use it in GitHub Desktop.
Time to decimal convert
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
| 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