Created
March 26, 2013 06:01
-
-
Save partlyhuman/5243453 to your computer and use it in GitHub Desktop.
Convert a sequence of hourly tasks and a regular work week into due dates.
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
#!/usr/bin/env ruby | |
require 'date' | |
class Date | |
def workday? | |
return !(self.saturday? or self.sunday?) | |
end | |
end | |
def tally_tasks(hrs_per_day, start_date=nil) | |
hrs_total = 0.0 | |
hrs_used_today = 0.0 | |
date = start_date || Date.today | |
while true | |
print "\nTask Hours> " | |
taskhrs = gets.strip.to_f | |
hrs_total += taskhrs | |
hrs_used_today += taskhrs | |
while hrs_used_today > hrs_per_day | |
date += 1 | |
hrs_used_today -= hrs_per_day if date.workday? | |
end | |
print "%s (%0.1fhr remain in day)\tTotal %0.1fhrs" % [date.to_s, hrs_per_day - hrs_used_today, hrs_total] | |
end | |
end | |
if __FILE__==$0 | |
if ARGV.length < 1 | |
abort "Usage: #{__FILE__} hours_allotted_per_day [starting_date]" | |
end | |
hrs_per_day = ARGV.shift.to_f | |
if ARGV.any? | |
start_date = Date.parse(ARGV.shift) | |
end | |
tally_tasks(hrs_per_day, start_date) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment