Created
February 4, 2016 16:42
-
-
Save binki/14ca6767d33b352530e2 to your computer and use it in GitHub Desktop.
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 python | |
import datetime | |
class Job(object): | |
def __init__(self, mean_hours, dates): | |
self.mean_hours = mean_hours | |
self.dates = dates | |
def parse_date(s): | |
dt = datetime.datetime.strptime(s, '%Y-%m-%d') | |
return datetime.date(dt.year, dt.month, dt.day) | |
def date_range(start, end): | |
while start <= end: | |
yield start | |
start += datetime.timedelta(1) | |
jobs = [ | |
Job(4, date_range(parse_date('2016-02-04'), parse_date('2016-02-05'))), | |
Job(8, date_range(parse_date('2016-02-05'), parse_date('2016-03-01'))), | |
] | |
for queried_date_s in ['2016-02-05', '2016-02-20']: | |
queried_date = parse_date(queried_date_s) | |
print('Hours for %s are %d' % (queried_date_s, sum([job.mean_hours for job in jobs if queried_date in job.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
Hours for 2016-02-05 are 12 | |
Hours for 2016-02-20 are 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment