-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibdate.py
51 lines (41 loc) · 1.26 KB
/
libdate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/env python3
import datetime
import logging
import pprint
import pandas
import os
# Hash to hold module level data
resources = {}
def daynames():
key = 'daynames'
if key not in resources:
resources[key] = ( 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat', 'Sun', )
return resources[key]
def holidays():
''' list of datetime.date values for holidays
'''
key = 'holidays'
if key not in resources:
filename = os.environ['TRIAGE_HOLIDAYS_FILE']
df = pandas.read_csv( filename ).squeeze( 'columns' )
dti = pandas.to_datetime( df )
# for d in dti:
# logging.debug( pprint.pformat( d ) )
resources[key] = dti
return resources[key]
def get_workdays( start, end ):
''' list of dates from start to end excluding weekends and holidays
start: string or datetime object
end: string or datetime object
'''
return pandas.bdate_range(
start = start,
end = end,
freq = 'C',
holidays = list( holidays() ),
)
if __name__ == '__main__':
start = datetime.date.today()
end = start + datetime.timedelta( days=90 )
for i,day in enumerate( get_workdays( start, end ) ):
print( f'{i:02d} {day} {daynames()[day.weekday()]}' )