问题描述
我正在寻找一种方法来确定给定的日期是否是假日,给定了假日日历。
具体来说,您可以说 is_holiday(datetime.date,USA)
,这将回答给定日期是否是名为美国的日历的假日。
我知道所有年份的所有假期都没有这种做法。例如,虽然圣诞节一直是12月25日,为了联邦政府的目的,有时我们庆祝(即不是一个工作日)在12月24日,有时在26日。 Similary,犹太节假日(例如)每年迁移(相对于公历)。
我不是每个假期的计算。我想知道更多,如果有一些接受,标准的文件格式列出节假日一年,如果是,如果有任何模块 - 在Python中,具体来说,但我灵活 - 了解如何阅读所述格式。类似地,文件格式将定义周末 - 通常是星期六和星期日,但在某些地区可能是星期五和星期六等。
Mozilla在.ics中有一组格式。这可能让你开始。不幸的是,他们出去不同的日期范围。 还在(也位于)我不能保证其质量,不幸的是。
I'm looking for a way to figure out whether a given date is a "holiday," given some holiday calendar.
Specifically, you might say is_holiday (datetime.date, "USA")
which would answer whether the given date is a holiday for the calendar named "USA."
I recognize that there's no trivial way of doing this for all holidays for all years. For example, while Christmas is always the 25th of December, for federal government purposes, sometimes we celebrate (i.e., it's not a business day) on the 24th of December, and sometimes on the 26th. Similary, Jewish holidays (for example) migrate yearly (relative to the Gregorian Calendar).
I'm not looking for calculations for each holiday. I'm wondering more if there's some accepted, standard file format that lists holidays by year, and if so, if there's any modules - in Python, specifically, but I'm flexible - that understand how to read said format. Similarly, the file format would define weekends - which are normally Saturday and Sunday, but in certain regions it may be Friday and Saturday, etc.
Mozilla has a set of user-contributed holiday files in .ics format. That may get you started. Unfortunately they go out to different date ranges. iCalShare also has holiday calendars in .ics format.
Note:
I've found in the past that a hierarchical approach works. e.g. check for a city holiday calendar, then a state calendar, then a country calender.
There's a Python module for reading .ics files called icalendar(also on pypi). I can't vouch for its quality, unfortunately.
这篇关于假日日历,文件格式,et al的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!