检测美国假期 [英] Detecting a US Holiday

查看:197
本文介绍了检测美国假期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最简单的方法是确定一个日期是否是美国在Python的假期?似乎有各种各样的日历和网络服务列出了各国的假期,但是我还没有发现任何具体到美国的银行。

What's the simplest way to determine if a date is a U.S. bank holiday in Python? There seem to be various calendars and webservices listing holidays for various countries, but I haven't found anything specific to banks in the U.S.

推荐答案

p>一些一般意见:

我不认为@ ast4真的意味着第n个月算法的第n周的第n天。 第n个月的第n个星期的概念是引人注意的(像ISO日历)。我从未见过第n个星期定义的假期。马丁·路德·金日是Nth weekday in month节假日的例子:

I don't think that @ast4 really means "nth day of nth week of nth month algorithm". The notion of "nth week in nth month" is mind-snapping (like the "ISO calendar"). I've never seen a holiday defined in terms of "nth week". Martin Luther King Day is an example of the"Nth weekday in month" type of holiday:

MONDAY, ...., SATURDAY = range(7)
JAN, ....., DEC = range(1, 12)

Holiday("Martin L King's Birthday", type='floating',
    ordinal=3, weekday=MON, month=JAN)
Holiday("Memorial Day", type='floating',
    ordinal=-1, weekday=MON, month=MAY)

美国没有复活节假期。定义并不困难:

The USA doesn't have Easter-related holidays. Definition is not difficult:

Holiday("Good Friday", type='moveable',
    base='gregorian_easter', delta_days=-2)
Holiday("Easter Monday", etc, delta_days=1)
# Some states in Australia used to have Easter Tuesday (no kidding)
Holiday("Easter Tuesday", etc, delta_days=2)

基础的想法可用于迎接月球新的一年,实际上是任何一个偏离基准日期需要特殊程序来计算的假期。

The 'base' idea can be used to cater for lunar new year, in fact any holiday that is an offset from a base date that needs a special procedure to calculate it.

所谓的静态假期并不固定当固定日期是星期六或星期日,甚至可能消失(无休止工作):

The so-called "static" holidays are not fixed when the "fixed" date is a Saturday or Sunday and may even vanish (no alternative day off work):

# Americans will get a day off on Friday 31 Dec 2010
# because 1 Jan 2011 is a Saturday.
Holiday("New Year's Day", type='fixed',
    day=1, month=JAN, sat_adj=-1, sun_adj=????)

# Australia observes ANZAC Day on the day, with no day off
# if the fixed date falls on a weekend.
Holiday("ANZAC Day", type='fixed', day=25, month=APR, sat_adj=0, sun_adj=0)

# Two consecutive "fixed" holidays is OK; three would need re-thinking.
# Australia again:
Holiday("Christmas Day", type='fixed', day=25, month=DEC, sat_adj=2, sun_adj=1)
Holiday("Boxing Day",    type='fixed', day=26, month=DEC, sat_adj=2, sun_adj=2)

我确定有办法指定不符合上述规定的假期...任何这样的消息是受欢迎的。

I'm sure there are ways of specifying holidays that aren't catered for by the above rules ... any such news is welcome.

这篇关于检测美国假期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆