-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_business_day.py
31 lines (18 loc) · 1.12 KB
/
custom_business_day.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
# ----------------------------------------------------------------------------------------------
# Using CustomBusinessDay, finds previous working day, if today is holiday, else returns today.
# --------------------------------------------------------------------------------------------
from pandas.tseries.offsets import CustomBusinessDay
from datetime import datetime
cust_business_day = CustomBusinessDay(holidays=[datetime.date(datetime(2018, 1, 4)),
datetime.date(datetime(2018, 1, 3)),
datetime.date(datetime(2018, 1, 1)),
datetime.date(datetime(2017, 12, 29))],
weekmask='Mon Tue Wed Thu Fri')
#date = datetime.date(datetime(2018, 1, 5))
date = datetime.date(datetime(2017, 12, 30))
def _get_working_day(date, cust_business_day):
if (date in cust_business_day.holidays or date.weekday()> 4):
date = (date - 1 * cust_business_day).date()
return date
date = _get_working_day(date, cust_business_day)
print(str(date))