Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return days
def get_variable_days(self, year):
days = super(CesarChavezDayMixin, self).get_variable_days(year)
days.extend(self.get_chavez_day(year))
return days
class DayAfterChristmasNoFloatMixin(Calendar):
"""26th of December - but doesn't ever float"""
def get_day_after_christmas(self, year):
days = (date(year, 12, 26), "Day After Christmas")
return days
class PatriotsDayMixin(Calendar):
"""3rd Monday of April"""
def get_patriots_day(self, year):
days = (self.get_nth_weekday_in_month(year, 4, MON, 3),
"Patriots Day")
return days
class Alabama(UnitedStates, WesternCalendar, FloatToNearestWeekdayMixin):
"Alabama"
include_confederation_day = True
def get_variable_days(self, year):
days = super(Alabama, self).get_variable_days(year)
days = self.float(days)
days.extend([
(Alabama.get_nth_weekday_in_month(year, 6, MON, 1),
WEEKEND_DAYS = (SAT, SUN)
class IslamicCalendar(IslamicMixin, Calendar):
"""
Islamic calendar
"""
class IslamoWesternCalendar(IslamicMixin, WesternMixin, Calendar):
"""
Mix of Islamic and Western calendars.
When countries have both Islamic and Western-Christian holidays.
"""
FIXED_HOLIDAYS = Calendar.FIXED_HOLIDAYS
class CesarChavezDayMixin(Calendar):
"""31st of March, float to 1st April if Monday"""
def get_chavez_day(self, year):
days = [(date(year, 3, 31), "Cesar Chavez Day")]
if date(year, 3, 31).weekday() == SUN:
days.append((date(year, 4, 1), "Cesar Chavez Day (Observed)"))
return days
def get_variable_days(self, year):
days = super(CesarChavezDayMixin, self).get_variable_days(year)
days.extend(self.get_chavez_day(year))
return days
class DayAfterChristmasNoFloatMixin(Calendar):
"""26th of December - but doesn't ever float"""
def get_day_after_christmas(self, year):
days = (date(year, 12, 26), "Day After Christmas")
return days
class PatriotsDayMixin(Calendar):
"""3rd Monday of April"""
def get_patriots_day(self, year):
days = (self.get_nth_weekday_in_month(year, 4, MON, 3),
"Patriots Day")
return days
class Alabama(UnitedStates, WesternCalendar, FloatToNearestWeekdayMixin):
"Alabama"
(date(year, 5, 1), self.labour_day_label)
)
return days
def get_variable_days(self, year):
days = super().get_variable_days(year)
new_year = date(year, 1, 1)
if self.include_new_years_day and self.shift_new_years_day:
if new_year.weekday() in self.get_weekend_days():
days.append((
self.find_following_working_day(new_year),
"New Year shift"))
return days
class WesternCalendar(WesternMixin, Calendar):
"""
A Christian calendar using Western definition for Easter.
"""
class OrthodoxCalendar(OrthodoxMixin, Calendar):
"""
A Christian calendar using Orthodox definition for Easter.
"""
class ChineseNewYearCalendar(ChineseNewYearMixin, Calendar):
"""
Chinese Calendar, using Chinese New Year computation.
"""
# There are regional exceptions to those week-end days, to define locally.
from ..core import Calendar
from ..core import FRI, SAT, IslamicMixin
from ..registry_tools import iso_register
@iso_register('QA')
class Qatar(IslamicMixin, Calendar):
"Qatar"
WEEKEND_DAYS = (FRI, SAT)
FIXED_HOLIDAYS = (
(12, 18, "National Day"),
)
include_start_ramadan = True
include_eid_al_fitr = True
length_eid_al_fitr = 4
include_eid_al_adha = True
length_eid_al_adha = 4
elif christmas_day == FRI:
day = date(year, 12, 24) # THU
elif christmas_day == SAT:
day = date(year, 12, 23) # THU
else: # christmas_day == SUN:
day = date(year, 12, 23) # FRI
return (day, self.label_washington_bday_observed)
def get_variable_days(self, year):
days = super(WashingtonsBirthdayInDecemberMixin, self) \
.get_variable_days(year)
days.append(self.get_washington_birthday(year))
return days
class CesarChavezDayMixin(Calendar):
"""31st of March, float to 1st April if Monday"""
def get_chavez_day(self, year):
days = [(date(year, 3, 31), "Cesar Chavez Day")]
if date(year, 3, 31).weekday() == SUN:
days.append((date(year, 4, 1), "Cesar Chavez Day (Observed)"))
return days
def get_variable_days(self, year):
days = super(CesarChavezDayMixin, self).get_variable_days(year)
days.extend(self.get_chavez_day(year))
return days
class DayAfterChristmasNoFloatMixin(Calendar):
"""26th of December - but doesn't ever float"""
def get_day_after_christmas(self, year):
if (date(year, 12, 25) in holiday_lookup and
date(year, 12, 24) in holiday_lookup and
date(year, 12, 25).weekday() == SAT):
new_holidays.append((date(year, 12, 23),
"Christmas Eve (Observed)"))
if (date(year, 12, 25) in holiday_lookup and
date(year, 12, 24) in holiday_lookup and
date(year, 12, 25).weekday() == MON):
new_holidays.append((date(year, 12, 26),
"Christmas Eve (Observed)"))
new_holidays.append((date(year, 12, 27),
"Christmas Day (Observed)"))
return holidays + new_holidays
class WashingtonsBirthdayInDecemberMixin(Calendar):
"""Floating observance, to give long weekend at christmas.
It's only observed in Georgia and Indiana.
"""
label_washington_bday_observed = "Washington's Birthday (Observed)"
def get_washington_birthday(self, year):
christmas_day = date(year, 12, 25).weekday()
if christmas_day == MON:
day = date(year, 12, 26) # TUE
elif christmas_day == TUE:
day = date(year, 12, 24) # MON
elif christmas_day == WED:
day = date(year, 12, 24) # TUE
elif christmas_day == THU:
day = date(year, 12, 26) # FRI
return days
class WesternCalendar(WesternMixin, Calendar):
"""
A Christian calendar using Western definition for Easter.
"""
class OrthodoxCalendar(OrthodoxMixin, Calendar):
"""
A Christian calendar using Orthodox definition for Easter.
"""
class ChineseNewYearCalendar(ChineseNewYearMixin, Calendar):
"""
Chinese Calendar, using Chinese New Year computation.
"""
# There are regional exceptions to those week-end days, to define locally.
WEEKEND_DAYS = (SAT, SUN)
class IslamicCalendar(IslamicMixin, Calendar):
"""
Islamic calendar
"""
class IslamoWesternCalendar(IslamicMixin, WesternMixin, Calendar):
"""
Mix of Islamic and Western calendars.
# Inauguration day
if UnitedStates.is_presidential_year(year - 1):
inauguration_day = date(year, 1, 20)
if inauguration_day.weekday() == SUN:
inauguration_day = date(year, 1, 21)
days.append((inauguration_day, "Inauguration Day"))
if self.include_thanksgiving_friday:
days.append(
self.get_thanksgiving_friday(year)
)
return days
class FloatToNearestWeekdayMixin(Calendar):
"Float Saturady to Friday, Sunday to Monday"
def float(self, holidays, year=0):
new_holidays = []
holiday_lookup = [x[0] for x in holidays]
for holiday in holidays:
if holiday[0].weekday() == SAT:
new_holidays.append((holiday[0] - timedelta(days=1),
holiday[1] + " (Observed)"))
elif holiday[0].weekday() == SUN:
new_holidays.append((holiday[0] + timedelta(days=1),
holiday[1] + " (Observed)"))
if year > 0 and date(year + 1, 1, 1).weekday() == SAT:
new_holidays.append((date(year, 12, 31,),
"New Years Day (Observed)"))
new_year = date(year, 1, 1)
if self.include_new_years_day and self.shift_new_years_day:
if new_year.weekday() in self.get_weekend_days():
days.append((
self.find_following_working_day(new_year),
"New Year shift"))
return days
class WesternCalendar(WesternMixin, Calendar):
"""
A Christian calendar using Western definition for Easter.
"""
class OrthodoxCalendar(OrthodoxMixin, Calendar):
"""
A Christian calendar using Orthodox definition for Easter.
"""
class ChineseNewYearCalendar(ChineseNewYearMixin, Calendar):
"""
Chinese Calendar, using Chinese New Year computation.
"""
# There are regional exceptions to those week-end days, to define locally.
WEEKEND_DAYS = (SAT, SUN)
class IslamicCalendar(IslamicMixin, Calendar):
"""
Islamic calendar