Python实现节假日判断,手动添加后续节假日
程序员文章站
2022-03-03 09:56:59
...
话不多说,安装 chinese_calendar 库可以实现,是不是节假日的判断,但是这个日期只能到2020年12月31日,2021年的不行,如果作者未发布版本的时候,可自己修改。
修改位置位于 Lib/site-packages/chinese_calendar/constants.py
修改内容,比如添加2021年的节假日:
holidays = {
#新增
datetime.date(year=2021, month=1, day=1): Holiday.new_years_day.value,
datetime.date(year=2021, month=2, day=11): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=12): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=13): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=14): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=15): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=16): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=17): Holiday.spring_festival.value,
datetime.date(year=2021, month=4, day=3): Holiday.tomb_sweeping_day.value,
datetime.date(year=2021, month=4, day=4): Holiday.tomb_sweeping_day.value,
datetime.date(year=2021, month=4, day=1): Holiday.tomb_sweeping_day.value,
datetime.date(year=2021, month=5, day=2): Holiday.labour_day.value,
datetime.date(year=2021, month=5, day=3): Holiday.labour_day.value,
datetime.date(year=2021, month=5, day=4): Holiday.labour_day.value,
datetime.date(year=2021, month=5, day=5): Holiday.labour_day.value,
datetime.date(year=2021, month=6, day=12): Holiday.dragon_boat_festival.value,
datetime.date(year=2021, month=6, day=13): Holiday.dragon_boat_festival.value,
datetime.date(year=2021, month=6, day=14): Holiday.dragon_boat_festival.value,
datetime.date(year=2021, month=9, day=19): Holiday.mid_autumn_festival.value,
datetime.date(year=2021, month=9, day=20): Holiday.mid_autumn_festival.value,
datetime.date(year=2021, month=9, day=21): Holiday.mid_autumn_festival.value,
datetime.date(year=2021, month=10, day=1): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=2): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=3): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=4): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=5): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=6): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=7): Holiday.national_day.value,
}
workdays = {
#新增
datetime.date(year=2021, month=2, day=7): Holiday.spring_festival.value,
datetime.date(year=2021, month=2, day=20): Holiday.spring_festival.value,
datetime.date(year=2021, month=4, day=25): Holiday.labour_day.value,
datetime.date(year=2021, month=5, day=8): Holiday.labour_day.value,
datetime.date(year=2021, month=9, day=18): Holiday.mid_autumn_festival.value,
datetime.date(year=2021, month=9, day=26): Holiday.national_day.value,
datetime.date(year=2021, month=10, day=9): Holiday.national_day.value,
}
就可以了。
上一篇: python 获取节假日
下一篇: vue directives指令总结