Created
July 24, 2014 23:02
-
-
Save winny-/052f5c5c9f8385c738ac to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
def duration_to_hours(duration): | |
if duration.isdigit(): | |
# Default to minutes | |
return float(duration) / 60.0 | |
def get_unit(unit): | |
nonlocal duration | |
if unit in duration: | |
if duration[-1] == unit: | |
result = float(duration[:-1]) | |
else: | |
result, duration = duration.split(unit) | |
result = float(result) | |
else: | |
result = 0.0 | |
return result | |
hours = get_unit('h') | |
minutes = get_unit('m') | |
seconds = get_unit('s') | |
hours = hours + minutes/60.0 + seconds/60.0/60.0 | |
return hours | |
if __name__ == '__main__': | |
import sys | |
print(duration_to_hours(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment