티스토리 뷰
pip install tox
pip install workalendar==2.4.0
class SouthKorea(WesternCalendar, ChineseNewYearCalendar):FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + ((3, 1, "Independence Day"),(5, 5, "Children's Day"),(6, 6, "Memorial Day"),(8, 15, "Liberation Day"),(10, 3, "National Foundation Day"),(10, 9, "Hangul Day"),(12, 25, "Christmas Day"))chinese_new_year_label = "Korean New Year's Day"include_chinese_new_year_eve = Truechinese_new_year_eve_label = "Korean New Year's Day"include_chinese_second_day = Truechinese_second_day_label = "Korean New Year's Day"def get_variable_days(self, year):days = super(SouthKorea, self).get_variable_days(year)days.extend([(ChineseNewYearCalendar.lunar(year, 4, 8), "Buddha's Birthday"),(ChineseNewYearCalendar.lunar(year, 8, 14), "Midautumn Festival"),(ChineseNewYearCalendar.lunar(year, 8, 15), "Midautumn Festival"),(ChineseNewYearCalendar.lunar(year, 8, 16), "Midautumn Festival")])return days
사용하는 방법을 예를 들면, 공휴일인지 아닌지 체크를 할 때 core.py에 있는 아래의 함수를 이용한다.
def is_holiday(self, day, extra_holidays=None):"""Return True if it's an holiday.n addition to the regular holidays, you can add exceptions.By providing ``extra_holidays``, you'll state that these dates **are**holidays, even if not in the regular calendar holidays (or weekends)."""# a little exception: chop the datetime typeif type(day) is datetime:day = day.date()if extra_holidays and day in extra_holidays:return True
return day in self.holidays_set(day.year)
실제 사용할 때
calendar = SouthKorea()calendar.is_holiday(확인하고싶은날짜)
참고
https://github.com/peopledoc/workalendar
'Programming > Python' 카테고리의 다른 글
[Python] 날짜로 요일구하기 (0) | 2019.01.10 |
---|---|
[Python] 지수/로그 (0) | 2018.09.23 |
[Python] 수치연산 (0) | 2018.09.22 |
[Python] 수학 모듈 (0) | 2018.09.19 |
[Python] timedelta 클래스 (0) | 2018.09.16 |
댓글