Added module find date range to display for a given date
This commit is contained in:
parent
7848c972f8
commit
47279f9282
63
workdays.py
Normal file
63
workdays.py
Normal file
@ -0,0 +1,63 @@
|
||||
import datetime as dt
|
||||
|
||||
holidays = [
|
||||
"2017-01-01", "2017-05-29", "2017-07-04", "2017-09-04", "2017-11-24",
|
||||
"2017-11-25", "2017-12-25",
|
||||
"2018-01-01", "2018-05-28", "2018-07-04", "2018-09-03", "2018-11-22",
|
||||
"2018-11-23", "2018-12-25",
|
||||
"2019-01-01", "2019-05-27", "2019-07-04", "2019-09-02", "2019-11-28",
|
||||
"2019-11-29", "2019-12-25",
|
||||
"2020-01-01", "2020-05-25", "2020-07-03", "2020-09-07", "2020-11-26",
|
||||
"2020-11-27", "2020-12-25",
|
||||
"2020-12-31", "2021-05-31", "2021-07-05", "2021-09-06", "2021-11-25",
|
||||
"2021-11-26", "2021-12-25",
|
||||
"2021-12-31", "2022-05-30", "2022-07-04", "2022-09-05", "2022-11-24",
|
||||
"2022-11-25", "2022-12-24",
|
||||
"2023-01-02", "2023-05-29", "2023-07-04", "2023-09-04", "2023-11-22",
|
||||
"2023-11-23", "2023-12-26",
|
||||
"2024-01-01", "2024-05-27", "2024-07-04", "2024-09-02", "2024-11-28",
|
||||
"2024-11-29", "2024-12-25",
|
||||
"2025-01-01", "2025-05-26", "2025-07-04", "2025-09-01", "2025-11-27",
|
||||
"2025-11-28", "2025-12-25",
|
||||
]
|
||||
|
||||
|
||||
def is_holiday(day):
|
||||
return day.strftime('%Y-%m-%d') in holidays
|
||||
|
||||
|
||||
def is_workday(day):
|
||||
return (not is_holiday(day)) and day.weekday() < 5
|
||||
|
||||
|
||||
def not_workday(day):
|
||||
return is_holiday(day) or day.weekday() > 4
|
||||
|
||||
|
||||
def start_day(day):
|
||||
start = day
|
||||
while True:
|
||||
start -= dt.timedelta(days=1)
|
||||
if is_workday(start) or start.weekday() == 5:
|
||||
start += dt.timedelta(days=1)
|
||||
return start
|
||||
|
||||
|
||||
def end_day(day):
|
||||
start = day
|
||||
while True:
|
||||
start += dt.timedelta(days=1)
|
||||
if is_workday(start) or start.weekday() == 6:
|
||||
start -= dt.timedelta(days=1)
|
||||
return start
|
||||
|
||||
|
||||
def get_date_range(date=''):
|
||||
if date == '':
|
||||
today = dt.datetime.now().date()
|
||||
else:
|
||||
today = dt.datetime.strptime(date, '%Y-%m-%d').date()
|
||||
return [start_day(today), end_day(today)]
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
Loading…
Reference in New Issue
Block a user