You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a sloppy coder, sorry! Self-taught and a horrible mix between OOP and not.
I needed to do two things...
Use a subset of holidays - specifically of German holidays - inorder to use only holidays observed by a particular institution; and
Fix the failure to report a Monday (and maybe Tuesday at Xmas) as a non-work day when a holiday falls at the weekend.
I haven't time to contribute formally to the project, but here is my code which perhaps others may craft into something more formally acceptable:
from datetime import date, timedelta, datetime
from workalendar.europe import Germany
dif = timedelta(days = +1)
def holdate(datetocheck, filteredhols):
for hol in filteredhols:
if hol[0] == datetocheck:
return True
return False
def day_in_lieu(datetocheck):
hols = cal.holidays(datetocheck.year)
filteredhols = [hol for hol in hols if hol[1] in observedhols ]
if (datetocheck.weekday() == 0 and (holdate(datetocheck-dif, filteredhols) or holdate(datetocheck-(2*dif),filteredhols))) or (datetocheck.weekday() == 1 and holdate(datetocheck-(3*dif),filteredhols) and holdate(datetocheck-(2*dif),filteredhols)):
return True
return False
def mod_working_day(datetocheck,observedhols):
if datetocheck.weekday() < 5 and not day_in_lieu(datetocheck):
return True
return False
I am a sloppy coder, sorry! Self-taught and a horrible mix between OOP and not.
I needed to do two things...
I haven't time to contribute formally to the project, but here is my code which perhaps others may craft into something more formally acceptable:
example use:
observedhols = ['New year','Good Friday','Easter Monday','Labour Day','Christmas Day','Second Christmas Day']
cal = Germany()
mod_working_day(date(1999, 5, 3),observedhols) --> False
mod_working_day(date(1999, 12, 28),observedhols) --> False
mod_working_day(date(2023, 1, 2),observedhols) --> False
The text was updated successfully, but these errors were encountered: