Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Days in lieu when holiday falls on weekend #770

Open
andydoc opened this issue Apr 22, 2024 · 0 comments
Open

Days in lieu when holiday falls on weekend #770

andydoc opened this issue Apr 22, 2024 · 0 comments

Comments

@andydoc
Copy link

andydoc commented Apr 22, 2024

I am a sloppy coder, sorry! Self-taught and a horrible mix between OOP and not.
I needed to do two things...

  1. Use a subset of holidays - specifically of German holidays - inorder to use only holidays observed by a particular institution; and
  2. 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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant