Created
November 27, 2017 15:24
-
-
Save rietta/78d6cbafd6d1e62359c6cf8a7f2a82e9 to your computer and use it in GitHub Desktop.
Keep a copy in your ~/bin and chmod to 755. Now, you can compute nicely rounded hours at will from the command line.
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 ruby | |
## | |
# Convert hours to invoice time, which is rounded to 6 minute increments. | |
time_value = ARGV.last.to_s.strip | |
if time_value =~ /\A[0-9]*:[0-9]*\Z/ | |
time_elements = time_value.split(':') | |
minutes = time_elements.first.to_i * 60.0 + 1.0 * time_elements.last.to_f | |
elsif time_value.to_f > 0.0 | |
minutes = time_value.to_f * 60.0 | |
else | |
STDERR.puts "Usage: hours 2:50 or hours 2.534 or hours 2" | |
exit 1; | |
end | |
hours = (minutes / 60.0).round(1) | |
puts hours |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment