Skip to content

Instantly share code, notes, and snippets.

@karolmajta
Created May 8, 2012 10:52
Show Gist options
  • Save karolmajta/2634227 to your computer and use it in GitHub Desktop.
Save karolmajta/2634227 to your computer and use it in GitHub Desktop.
Utility to get all official public holidays in Poland for a given year.
from datetime import date, timedelta
FEASTS = (
(1, 1), # New Years Day
(1, 6), # Epiphany
(5, 1), # Work Day
(5, 3), # Constiturion Day
(8, 15), # Army Day
(11, 1), # All Saints
(11, 11), # Independence Day
(12, 25), # Christmas
(12, 26), # Christmas
)
def get_easter(year):
'''
Returns Easter as a date object.
'''
a = year % 19
b = year // 100
c = year % 100
d = (19 * a + b - b // 4 - ((b - (b + 8) // 25 + 1) // 3) + 15) % 30
e = (32 + 2 * (b % 4) + 2 * (c // 4) - d - (c % 4)) % 7
f = d + e - 7 * ((a + 11 * d + 22 * e) // 451) + 114
month = f // 31
day = f % 31 + 1
return date(year, month, day)
def get_moving_feasts(year):
'''
Returns all moving feasts in Polish calendar for given year.
'''
easter_sunday = get_easter(year)
easter_monday = easter_sunday + timedelta(days=1)
# get Pentecost
pentecost = easter_sunday + timedelta(days=49)
# get Corpus Christi
corpus_christi = easter_sunday + timedelta(days=60)
return (
easter_sunday,
easter_monday,
pentecost,
corpus_christi,
)
def get_feasts(year):
'''
Returns all feasts in Polish calendar for given year.
'''
feasts = map(lambda x: date(year, x[0], x[1]), FEASTS)
return tuple(feasts) + get_moving_feasts(year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment