Coder Social home page Coder Social logo

vacanza / python-holidays Goto Github PK

View Code? Open in Web Editor NEW
1.4K 17.0 457.0 12.25 MB

Generate and work with holidays in Python

Home Page: https://pypi.org/project/holidays

License: MIT License

Python 99.94% Makefile 0.06%
python holiday calendar holiday-api holiday-calculation

python-holidays's Introduction

holidays

A fast, efficient Python library for generating country- and subdivision- (e.g. state or province) specific sets of government-designated holidays on the fly. It aims to make determining whether a specific date is a holiday as fast and flexible as possible.

PyPI PyPI downloads PyPI version PyPI release date
CI/CD CI/CD status Documentation status
Code License Python supported versions Code style Code coverage
GitHub GitHub stars GitHub forks GitHub contributors GitHub last commit

Install

The latest stable version can always be installed or updated via pip:

$ pip install --upgrade holidays

The latest development (dev) version can be installed directly from GitHub:

$ pip install --upgrade https://github.com/vacanza/python-holidays/tarball/dev

All new features are always first pushed to dev branch, then released on main branch upon official version upgrades.

Documentation

The documentation is hosted on Read the Docs.

Quick Start

from datetime import date
import holidays

us_holidays = holidays.US()  # this is a dict-like object
# the below is the same, but takes a string:
us_holidays = holidays.country_holidays('US')  # this is a dict-like object

nyse_holidays = holidays.NYSE()  # this is a dict-like object
# the below is the same, but takes a string:
nyse_holidays = holidays.financial_holidays('NYSE')  # this is a dict-like object

date(2015, 1, 1) in us_holidays  # True
date(2015, 1, 2) in us_holidays  # False
us_holidays.get('2014-01-01')  # "New Year's Day"

The HolidayBase dict-like class will also recognize date strings and Unix timestamps:

'2014-01-01' in us_holidays  # True
'1/1/2014' in us_holidays    # True
1388597445 in us_holidays    # True

Some holidays may be only present in parts of a country:

us_pr_holidays = holidays.country_holidays('US', subdiv='PR')
'2018-01-06' in us_holidays     # False
'2018-01-06' in us_pr_holidays  # True

Please see the python-holidays documentation for additional examples and detailed information.

Available Countries

We currently support 152 country codes. The standard way to refer to a country is by using its ISO 3166-1 alpha-2 code, the same used for domain names, and for a subdivision its ISO 3166-2 code. Some countries have common or foreign names or abbreviations as aliases for their subdivisions. These are defined in the (optional) subdivisions_aliases attribute. Some of the countries support more than one language for holiday names output. A default language is defined by default_language (optional) attribute for each entity and is used as a fallback when neither user specified language nor user locale language available. The default language code is a ISO 639-1 code. A list of all languages supported by country is defined by supported_languages (optional) attribute. If there is no designated ISO 639-1 code then ISO 639-2 code can be used.

Many countries have other categories of holidays in addition to common (national-wide) holidays: bank holidays, school holidays, additional (paid or non-paid) holidays, holidays of state or public employees, religious holidays (valid only for these religions followers). A list of all categories supported by country is defined by supported_categories (optional) attribute.

The following is a list of supported countries, their subdivisions followed by their aliases (if any) in brackets, available languages and additional holiday categories. All countries support PUBLIC holidays category by default. All other default values are highlighted with bold:

Country Code Subdivisions Supported Languages Supported Categories
Albania AL      
Algeria DZ   ar, en_US, fr  
American Samoa AS Can also be loaded as country US, subdivision AS   UNOFFICIAL
Andorra AD Parishes: 02, 03, 04, 05, 06, 07, 08    
Angola AO   en_US, pt_AO, uk  
Argentina AR   en_US, es, uk  
Armenia AM   en_US, hy  
Aruba AW   en_US, nl, pap_AW, uk  
Australia AU States and territories: ACT (Australian Capital Territory), NSW (New South Wales), NT (Northern Territory), QLD (Queensland), SA (South Australia), TAS (Tasmania), VIC (Victoria), WA (Western Australia) en_AU, en_US, th BANK, HALF_DAY
Austria AT States: 1 (Burgenland, Bgld, B), 2 (Kärnten, Ktn, K), 3 (Niederösterreich, NÖ, N), 4 (Oberösterreich, OÖ, O), 5 (Salzburg, Sbg, S), 6 (Steiermark, Stmk, St), 7 (Tirol, T), 8 (Vorarlberg, Vbg, V), 9 (Wien, W) de, en_US, uk BANK
Azerbaijan AZ   az, en_US, uk WORKDAY
Bahamas BS      
Bahrain BH   ar, en_US  
Bangladesh BD      
Barbados BB      
Belarus BY   be, en_US  
Belgium BE   de, en_US, fr, nl, uk BANK
Belize BZ      
Bolivia BO Departments: B, C, H, L, N, O, P, S, T en_US, es, uk  
Bosnia and Herzegovina BA Entities and district: BIH (Federacija Bosne i Hercegovine, FBiH), BRC (Brčko distrikt, BD), SRP (Republika Srpska, RS) bs, en_US, sr, uk  
Botswana BW      
Brazil BR States: AC, AL, AM, AP, BA, CE, DF, ES, GO, MA, MG, MS, MT, PA, PB, PE, PI, PR, RJ, RN, RO, RR, RS, SC, SE, SP, TO   OPTIONAL
Brunei BN   en_US, ms, th  
Bulgaria BG   bg, en_US, uk SCHOOL
Burkina Faso BF      
Burundi BI      
Cambodia KH   en_US, km, th  
Cameroon CM      
Canada CA Provinces and territories: AB, BC, MB, NB, NL, NS, NT, NU, ON, PE, QC, SK, YT ar, en_CA, en_US, fr, th GOVERNMENT, OPTIONAL
Chad TD      
Chile CL Regions: AI, AN, AP, AR, AT, BI, CO, LI, LL, LR, MA, ML, NB, RM, TA, VS en_US, es, uk BANK
China CN   en_US, th, zh_CN, zh_TW HALF_DAY
Colombia CO   en_US, es, uk  
Costa Rica CR   en_US, es, uk OPTIONAL
Croatia HR   en_US, hr, uk  
Cuba CU   en_US, es, uk  
Curacao CW   en_US, nl, pap_CW, uk  
Cyprus CY   el, en_CY, en_US, uk BANK, OPTIONAL
Czechia CZ   cs, en_US, sk, uk  
Denmark DK   da, en_US, uk OPTIONAL
Djibouti DJ   ar, en_US, fr  
Dominica DM      
Dominican Republic DO   en_US, es, uk  
Ecuador EC   en_US, es, uk  
Egypt EG   ar, en_US  
El Salvador SV Departments: AH, CA, CH, CU, LI, MO, PA, SA, SM, SO, SS, SV, UN, US    
Estonia EE   en_US, et, uk  
Eswatini SZ      
Ethiopia ET   am, ar, en_US  
Finland FI   en_US, fi, sv_FI, uk UNOFFICIAL
France FR DOM/TOM: BL, GES, GP, GY, MF, MQ, NC, PF, RE, WF, YT en_US, fr, uk  
Gabon GA      
Georgia GE   en_US, ka, uk GOVERNMENT
Germany DE States: BB (Brandenburg), BE (Berlin), BW (Baden-Württemberg), BY (Bayern), HB (Bremen), HE (Hessen), HH (Hamburg), MV (Mecklenburg-Vorpommern), NI (Niedersachsen), NW (Nordrhein-Westfalen), RP (Rheinland-Pfalz), SH (Schleswig-Holstein), SL (Saarland), SN (Sachsen), ST (Sachsen-Anhalt), TH (Thüringen) de, en_US, th, uk CATHOLIC
Ghana GH      
Greece GR   el, en_US, uk HALF_DAY
Greenland GL   da, en_US, kl OPTIONAL
Guam GU Can also be loaded as country US, subdivision GU   UNOFFICIAL
Guatemala GT   en_US, es  
Haiti HT   en_US, es, fr_HT, ht OPTIONAL
Honduras HN   en_US, es, uk  
Hong Kong HK     OPTIONAL
Hungary HU   en_US, hu, uk  
Iceland IS   en_US, is, uk  
India IN States: AN, AP, AR, AS, BR, CG, CH, DH, DL, GA, GJ, HP, HR, JH, JK, KA, KL, LA, LD, MH, ML, MN, MP, MZ, NL, OD, PB, PY, RJ, SK, TN, TR, TS, UK, UP, WB    
Indonesia ID   en_US, id, uk GOVERNMENT
Iran IR   en_US, fa  
Ireland IE      
Isle of Man IM      
Israel IL   en_US, he, uk OPTIONAL, SCHOOL
Italy IT Provinces: AG (Agrigento), AL (Alessandria), AN (Ancona), AO (Aosta), AP (Ascoli Piceno), AQ (L'Aquila), AR (Arezzo), AT (Asti), AV (Avellino), BA (Bari), BG (Bergamo), BI (Biella), BL (Belluno), BN (Benevento), BO (Bologna), BR (Brindisi), BS (Brescia), BT (Barletta-Andria-Trani), BZ (Bolzano), CA (Cagliari), CB (Campobasso), CE (Caserta), CH (Chieti), CL (Caltanissetta), CN (Cuneo), CO (Como), CR (Cremona), CS (Cosenza), CT (Catania), CZ (Catanzaro), EN (Enna), FC (Forli-Cesena, Forlì-Cesena), FE (Ferrara), FG (Foggia), FI (Firenze), FM (Fermo), FR (Frosinone), GE (Genova), GO (Gorizia), GR (Grosseto), IM (Imperia), IS (Isernia), KR (Crotone), LC (Lecco), LE (Lecce), LI (Livorno), LO (Lodi), LT (Latina), LU (Lucca), MB (Monza e Brianza), MC (Macerata), ME (Messina), MI (Milano), MN (Mantova), MO (Modena), MS (Massa-Carrara), MT (Matera), NA (Napoli), NO (Novara), NU (Nuoro), OR (Oristano), PA (Palermo), PC (Piacenza), PD (Padova), PE (Pescara), PG (Perugia), PI (Pisa), PN (Pordenone), PO (Prato), PR (Parma), PT (Pistoia), PU (Pesaro e Urbino), PV (Pavia), PZ (Potenza), RA (Ravenna), RC (Reggio Calabria), RE (Reggio Emilia), RG (Ragusa), RI (Rieti), RM (Roma), RN (Rimini), RO (Rovigo), SA (Salerno), SI (Siena), SO (Sondrio), SP (La Spezia), SR (Siracusa), SS (Sassari), SU (Sud Sardegna), SV (Savona), TA (Taranto), TE (Teramo), TN (Trento), TO (Torino), TP (Trapani), TR (Terni), TS (Trieste), TV (Treviso), UD (Udine), VA (Varese), VB (Verbano-Cusio-Ossola), VC (Vercelli), VE (Venezia), VI (Vicenza), VR (Verona), VT (Viterbo), VV (Vibo Valentia). Cities: Andria, Barletta, Cesena, Forli (Forlì), Pesaro, Trani, Urbino    
Jamaica JM      
Japan JP   en_US, ja, th BANK
Jersey JE      
Jordan JO   ar, en_US  
Kazakhstan KZ      
Kenya KE      
Kuwait KW   ar, en_US  
Kyrgyzstan KG      
Laos LA   en_US, lo, th BANK, SCHOOL, WORKDAY
Latvia LV   en_US, lv, uk  
Lesotho LS      
Liechtenstein LI   de, en_US, uk BANK
Lithuania LT   en_US, lt, uk  
Luxembourg LU   de, en_US, fr, lb, uk  
Madagascar MG   en_US, mg, uk  
Malawi MW      
Malaysia MY States and federal territories: 01 (Johor, JHR), 02 (Kedah, KDH), 03 (Kelantan, KTN), 04 (Melaka, MLK), 05 (Negeri Sembilan, NSN), 06 (Pahang, PHG), 07 (Pulau Pinang, PNG), 08 (Perak, PRK), 09 (Perlis, PLS), 10 (Selangor, SGR), 11 (Terengganu, TRG), 12 (Sabah, SBH), 13 (Sarawak, SWK), 14 (WP Kuala Lumpur, KUL), 15 (WP Labuan, LBN), 16 (WP Putrajaya, PJY) en_US, ms_MY  
Maldives MV      
Malta MT   en_US, mt  
Marshall Islands (the) MH      
Mauritania MR      
Mexico MX   en_US, es, uk  
Moldova MD   en_US, ro, uk  
Monaco MC   en_US, fr, uk  
Montenegro ME      
Morocco MA   ar, en_US, fr  
Mozambique MZ   en_US, pt_MZ, uk  
Namibia NA      
Netherlands NL   en_US, nl, uk OPTIONAL
New Zealand NZ Regions and Special Island Authorities: AUK (Auckland, Tāmaki-Makaurau, AU), BOP (Bay of Plenty, Toi Moana, BP), CAN (Canterbury, Waitaha, CA), CIT (Chatham Islands Territory, Chatham Islands, Wharekauri, CI), GIS (Gisborne, Te Tairāwhiti, GI), HKB (Hawke's Bay, Te Matau-a-Māui, HB), MBH (Marlborough, MA), MWT (Manawatū Whanganui, Manawatū-Whanganui, MW), NSN (Nelson, Whakatū, NE), NTL (Northland, Te Taitokerau, NO), OTA (Otago, Ō Tākou, OT), STL (Southland, Te Taiao Tonga, SO), TAS (Tasman, Te tai o Aorere, TS), TKI (Taranaki, TK), WGN (Greater Wellington, Te Pane Matua Taiao, Wellington, Te Whanganui-a-Tara, WG), WKO (Waikato, WK), WTC (West Coast, Te Tai o Poutini, WC). Subregions: South Canterbury    
Nicaragua NI Departments: AN, AS, BO, CA, CI, CO, ES, GR, JI, LE, MD, MN, MS, MT, NS, RI, SJ en_US, es, uk  
Nigeria NG      
Northern Mariana Islands (the) MP Can also be loaded as country US, subdivision MP   UNOFFICIAL
North Macedonia MK      
Norway NO   en_US, no, uk  
Pakistan PK      
Palau PW     ARMED_FORCES, HALF_DAY
Panama PA      
Papua New Guinea PG      
Paraguay PY   en_US, es, uk GOVERNMENT
Peru PE   en_US, es, uk  
Philippines PH      
Poland PL   en_US, pl, uk  
Portugal PT Districts: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 30 en_US, pt_PT, uk OPTIONAL
Puerto Rico PR Can also be loaded as country US, subdivision PR   UNOFFICIAL
Romania RO   en_US, ro, uk  
Russia RU   en_US, ru  
Samoa WS      
San Marino SM      
Saudi Arabia SA   ar, en_US  
Serbia RS   en_US, sr  
Seychelles SC   en_SC, en_US  
Singapore SG      
Slovakia SK   en_US, sk, uk WORKDAY
Slovenia SI   en_US, sl, uk  
South Africa ZA      
South Korea KR   en_US, ko, th BANK
Spain ES Autonomous communities: AN, AR, AS, CB, CE, CL, CM, CN, CT, EX, GA, IB, MC, MD, ML, NC, PV, RI, VC en_US, es, uk  
Sweden SE   en_US, sv, uk  
Switzerland CH Cantons: AG, AI, AR, BL, BS, BE, FR, GE, GL, GR, JU, LU, NE, NW, OW, SG, SH, SZ, SO, TG, TI, UR, VD, VS, ZG, ZH de, en_US, fr, it, uk HALF_DAY, OPTIONAL
Taiwan TW   en_US, th, zh_CN, zh_TW  
Tanzania TZ   en_US, sw BANK
Thailand TH   en_US, th ARMED_FORCES, BANK, GOVERNMENT, SCHOOL, WORKDAY
Timor Leste TL   en_US, pt_TL, tet GOVERNMENT, WORKDAY
Tonga TO   en_US, to  
Tunisia TN   ar, en_US  
Turkey TR   en_US, tr, uk HALF_DAY
Ukraine UA   ar, en_US, uk WORKDAY
United Arab Emirates AE   ar, en_US  
United Kingdom GB Subdivisions: ENG (England), NIR (Northern Ireland), SCT (Scotland), WLS (Wales)    
United States Minor Outlying Islands UM Can also be loaded as country US, subdivision UM   UNOFFICIAL
United States of America (the) US States and territories: AK, AL, AR, AS, AZ, CA, CO, CT, DC, DE, FL, GA, GU, HI, IA, ID, IL, IN, KS, KY, LA, MA, MD, ME, MI, MN, MO, MP, MS, MT, NC, ND, NE, NH, NJ, NM, NV, NY, OH, OK, OR, PA, PR, RI, SC, SD, TN, TX, UM, UT, VA, VI, VT, WA, WI, WV, WY   UNOFFICIAL
United States Virgin Islands (the)   See Virgin Islands (U.S.)   UNOFFICIAL
Uruguay UY   en_US, es, uk BANK
Uzbekistan UZ   en_US, uk, uz  
Vanuatu VU      
Vatican City VA      
Venezuela VE   en_US, es, uk  
Vietnam VN      
Virgin Islands (U.S.) VI Can also be loaded as country US, subdivision VI   UNOFFICIAL
Zambia ZM      
Zimbabwe ZW      

Available Financial Markets

The standard way to refer to a financial market is to use its ISO 10383 MIC (Market Identifier Code) as a "country" code when available. The following financial markets are available:

Entity Code Info
European Central Bank ECB Trans-European Automated Real-time Gross Settlement (TARGET2)
ICE Futures Europe IFEU A London-based Investment Exchange holidays
New York Stock Exchange XNYS NYSE market holidays (used by all other US-exchanges, including NASDAQ, etc.)

Contributions

Issues and pull requests are always welcome. Please see here for more information.

License

Code and documentation are available according to the MIT License (see LICENSE).

python-holidays's People

Contributors

anthonykrose avatar antusystem avatar arkid15r avatar bkthomps avatar dependabot[bot] avatar dniemeijer avatar dr-prodigy avatar fav007 avatar fb22 avatar giladmaya avatar github-actions[bot] avatar gtrabanco avatar hugovk avatar jeannaudee avatar jusce17 avatar karl-henrik avatar kasya avatar kjhellico avatar mborsetti avatar mmontel-wgs avatar nadime avatar nickyspag avatar pietervdw115 avatar pmpbaptista avatar ppsyrius avatar rafelbev avatar rosi2143 avatar sugatoray avatar tedtad avatar vlt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-holidays's Issues

Easter Sunday is a holiday in all of Germany, not only in Brandenburg.

For some reason I don't understand python-holidays only defines Easter Sunday for country == 'DE' as holiday in prov = 'BB' which I guess means Brandenburg. Easter Monday and Good Friday are (correctly) set up for entire Germany.

I'm not aware of any special regulation in Brandenburg, so I'd say this is a bug. Of course, Easter Sunday is always a Sunday, so the consequences aren't that great from a work time perspective, but anyhow...

P.S.: https://www.youtube.com/watch?v=kdwKbiMyvu0

P.P.S: Same issue with Pentecost (Pfingstsonntag)...

Determining true holiday, verses observed.

When generating the US holidays for 2022, the observed new year's day is in 2021 (Dec. 31).

us_holidays = holidays.US()
date(2022, 1, 1) in us_holidays

The observed new year's day in not among the us_holidays. To have the observed holiday, you need to also populate 2021:

date(2021, 1, 1) in us_holidays

Retrive calendar by country name/abbreviation

In many occasions the country for which we want to retrive the calendar is a parameter of the program/analysis itself so don't want to hardcode an infinite list of if ... elif.

Is it possible to have a function like get_calendar(country), from which we can retrive a calendar class by passing a string with the country name/abbreviation?

Thanks

setting state/province using CountryHoliday

Assuming that, CountryHoliday is used as described in the README and the country is not know until runtime (e.g. it is read from a config or user input):

import holidays

country = "DE"  # from sys.argv, for example
ch = holidays.CountryHoliday(country)

This of course yields a perfectly fine instance. The problem comes up when the state or province is also relevant. Since CountryHoliday returns an instance, there is no way to add a state, which is set using the constructor.

A couple of workarounds:

  • use type() or .__class__ to get the class; create a new instance
  • use getattr(holidays, country) to get the class directly, skips the nice error handling

Neither of those seem like a sleek and easy to understand solution to me.

To resolve this, I propose that all keyword arguments to CountryHoliday should be passed onto the class, like so (omitting error handling):

def CountryHoliday(country, **kwargs):
    country_holiday = globals()[country](**kwargs)
    return country_holiday

holidays_de_he = CountryHoliday("DE", prov="HE")

This enables setting the state/province and of course all other options like expand or observed, even when using the very friendly CountryHoliday. The external API stays stable, since arguments are only added and the single existing one just stays in place.

What do you think? :) I am happy to code up a quick PR including docs and a test, if you'd like.

Option for ignoring "unobserved" holidays

It might be nice to allow for not adding holidays that are not going to be observed on their normal date. I'm guessing that this only happens when the actual holiday falls on a weekend so maybe it doesn't matter.

Should province and state be synonyms?

Hi,

shouldn't states and provinces be synonyms so that they can be used interchangeably?

For example, so that
holidays.DE(state='BW') == holidays.DE(prov='BW') # True

Regards,
Achim

pull date range

Hi

I am a newbie to this library and I tried to find the holidays in a date range that started from date A to date B in Canada.
for example, this is what I would do with the U.S. holidays:

from pandas.tseries.holiday import USFederalHolidayCalendar as calendar
cal = calendar()
holidays = cal.holidays(start='05-13-2014, end=05-13-2016)
print(holidays)

I would appreciate if you help me with that.

Regards

Brazilian national and state holidays

Could it be possible to include Brazilian national (federal) and state holidays? I am working on an app where I need to calculate odd workdays, that is single weekdays squeezed between holidays, or holiday and weekend. What I need for now is the federal + the state of Espírito Santo.

Not able to access Indian Holidays

I am trying to run holidays.IND() for Indian Holidays but it is showing me following error:

AttributeError Traceback (most recent call last)
in ()
----> 1 holidays.IND()

AttributeError: module 'holidays' has no attribute 'IND'

please suggest any solution for this.

Adding Israeli holidays

I'd like to suggest adding Israeli holidays.
Note that Israel has a few different calendars for holidays: they are not different between states (no states in Israel) but rather between religions: Jewish, Christian and Muslim holidays are all different.
Furthermore, they don't all follow the Georgian calendar. Libraries such as pyluach might be convenient in implementing these holidays.
I will try to address the issue, and update accordingly.

Reformationstag Germany

Reformationstag 31.10. is always a public holiday in Germanys state Brandenburg (BR)
Furthermore in 2017 it is a public holiday in all states (500. Anniversary of Martin Luthers 95 Thesis)

Add requirements file

pip install holidays fails if python-dateutil is not already present

I believe the project needs to include a requirement file to ensure the dependencies get installed.

This is essential for including this package into any automated deployments...

Holiday object doesn't generate holidays until __contains__() ran

As shown below holidays won't appear in the object until I check if a date is in the holiday object.

Python 2.7.5 (default, Oct 11 2015, 17:47:16) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import holidays
>>> print holidays.__version__
0.5
>>> h = holidays.UnitedStates()
>>> h
{}
>>> datetime.datetime.now() in h
False
>>> h
{datetime.date(2016, 11, 24): 'Thanksgiving', datetime.date(2016, 2, 15): "Washington's Birthday", datetime.date(2016, 7, 4): 'Independence Day', datetime.date(2016, 9, 5): 'Labor Day', datetime.date(2016, 12, 25): 'Christmas Day', datetime.date(2016, 1, 1): "New Year's Day", datetime.date(2016, 10, 10): 'Columbus Day', datetime.date(2016, 1, 18): 'Martin Luther King, Jr. Day', datetime.date(2016, 12, 26): 'Christmas Day (Observed)', datetime.date(2016, 11, 11): 'Veterans Day', datetime.date(2016, 5, 30): 'Memorial Day'}

setup.py fails in non-utf8 locales

When setup.py us run in non-unicode locales, it crashes with the error below. This is caused by the implicit use of codecs. To find the version number, holidays.py is read using the codecs module, but no codec is specified. Because of this, the codec used depends on the locale, which is ascii for non-unicode locales. Holidays.py contains many non-ascii characters in the holiday names, so this fails.

Non-unicode locales are the default in most minimal setups (such as docker images), so this has quite a bit of impact. Fortunately the fix is trivial; I'll add a merge request.

Collecting holidays (from -r requirements.txt (line 22))
  Downloading holidays-0.6.tar.gz (40kB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-a2dby65n/holidays/setup.py", line 21, in <module>
        fd.read(), re.MULTILINE).group(1)
      File "/usr/lib/python3.5/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16417: ordinal not in range(128)

Workaround for those who depend on the pypi version (requires the C.UTF-8 locale to be generated on your system. Ubuntu docker image has that by default.)

LC_CTYPE=C.UTF-8 python setup.py install  # or whatever pip command you need

Ad-hoc UK bank holidays not included

The UK definitions are based on a calculation of when holidays would fall in a given year. However this fails to take into account additional bank holidays. For example 29 April 2011 was a bank holiday but the library reports that it was not.

Queen's birthday in AU/Queensland is wrong

Yes, we are bit odd state that we celebrate her birthday on a different date compared to all other Australian states, just like WA does.

We used to have same exact date up until 2012 (that we decided to celebrate twice) than turned back to normal for a few years. In 2016, we again decided that we could move her birthday to completely different month, first Monday of October (same as in 2012) and it remained permanent (so far).

https://www.timeanddate.com/holidays/australia/queens-birthday

PR will be provided within the cumulative merge #84.

Holidays for state BW in Germany are missing (?)

Hi,

thanks for coming up with this nice package, I am using 0.9.5 from Debian :-)

I just realized, that the holidays for BW in Germany are incomplete:

import holidays
        
bw_holidays = holidays.DE(state='BW',years=2018)

for date, name in sorted(bw_holidays.items()):
    print(date, name)

results in


rd@b370:~$ python3 test-holidays.py 
2018-01-01 Neujahr
2018-03-30 Karfreitag
2018-04-02 Ostermontag
2018-05-01 Maifeiertag
2018-05-10 Christi Himmelfahrt
2018-05-21 Pfingstmontag
2018-10-03 Tag der Deutschen Einheit
2018-12-25 Erster Weihnachtstag
2018-12-26 Zweiter Weihnachtstag
rd@b370:~$ 

A full list is give e.g. here:

https://www.schulferien.org/Feiertage/Feiertage_Baden_Wuerttemberg.html

Adding a Singapore Calendar

Similarly to what has been requested for Israel, Singapore public holidays are made of fixed dates (New Year, Labour day, National Day and Christmas). Other public holidays are "religious" celebrations taken from muslim, Hinddu and Buddhist calendars). These "religious" celebrations vary every year but the Ministry of Manpower in Singapore publishes the official public holidays with 1 year in advance (currently published are 2018 and 2019).
There is no accurate way to calculate (or I do not know it) what will be the dates for these religious holidays for 2020 and beyond. Which means that this library, if it is created will have to be updated at the beginning or every year.

I have prepared a SG class covering 2018 and 2019. I could submit it but I will need some guidance as I am a newbie to all this (Github, python,...)
Here is the code:

`# -- coding: utf-8 --

class Singapore(HolidayBase):
PROVINCES = []

def __init__(self, **kwargs):
    self.country = 'SG'
    HolidayBase.__init__(self, **kwargs)

def _populate(self, year):
# Singapore became independent on 9th August 1965
    if year < 1965:
        return

    # New Year's Day
    name = "New Year's Day"
    jan1 = date(year, 1, 1)
    self[jan1] = name
    # If New year falls on Sunday, Monday becomes public Holiday
    if self.observed and jan1.weekday() == 6:
        self[date(year, 1, 2)] = name + " (Observed)"

    # Chinese New Year
    name = "Chinese New Year (1)"
    if year == 2018:
        self[date(year, 2, 16) = name
    if year == 2019:
        self[date(year, 2, 5) = name

    # Chinese New Year
    name = "Chinese New Year (2)"
    if year == 2018:
        self[date(year, 2, 17) = name
    if year == 2019:
        self[date(year, 2, 6) = name

    # Good Friday
    self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"

    # Labour Day
    name = "Labour Day"
    # Started being celebrated in 1960 after People Action Party went into power
    # Reference Wikipedia (Labour Day Singapore)
    if year >= 1960:
        self[date(year, 5, 1) = name
    # if Labour day falls on a Sunday, Monday is observed
    if self.observed and may1.weekday() == 6:
        self[date(year, 5, 2)] = name + " (Observed)"

    # Vesak Day
    name = "Vesak day"
    if year == 2018:
        self[date(year, 5, 29) = name
    if year == 2019:
        self[date(year, 5, 19) = name

    # Hari Raya Puasa
    # End of Ramadan
    name = "Hari Raya Puasa"
    if year == 2018:
        self[date(year, 6, 15) = name
    if year == 2019:
        self[date(year, 6, 5) = name

    # National Day
    if year > 1965:
        name = "National Day"
        aug9 = date(year, 8, 9)
        self[feb6] = name
    # if National day falls on a Sunday, Monday is observed
        if self.observed and year >= 1965 and aug9.weekday() == 6:
            self[date(year, 8, 10)] = name + " (Observed)"

    # Hari Raya Hadji
    # First day of muslim pilgrimage to Mecca
      name = "Hari Raya Hadji"
      if year == 2018:
          self[date(year, 8, 22) = name
      if year == 2019:
          self[date(year, 8, 11) = name

    # Deepavali
      name = "Deepavali"
      if year == 2018:
          self[date(year, 11, 6) = name
      if year == 2019:
          self[date(year, 10, 27) = name

    # Christmas Day
    name = "Christmas Day"
    dec25 = date(year, 12, 25)
    self[dec25] = name
    # if Christms day falls on a Sunday, Monday is observed
    if self.observed and dec25.weekday() == 6 :
        self[date(year, 12, 26)] = name + " (Observed)"

class SG(Singapore):
pass
`

Add support for Swedish Holidays

Doing some googling the following could be used as data source:
http://api.dryg.net/dagar/v2.1/YYYY, http://api.dryg.net/dagar/v2.1/YYYY/MM, http://api.dryg.net/dagar/v2.1/YYYY/MM/DD
Result for 2017

{
  "cachetid": "2017-05-10 14:05:17",
  "version": "2.1",
  "uri": "/dagar/v2.1/2017",
  "startdatum": "2017-01-01",
  "slutdatum": "2017-12-31",
  "dagar": [
    {
      "datum": "2017-01-01",
      "veckodag": "Söndag",
      "arbetsfri dag": "Ja",
      "röd dag": "Ja",
      "vecka": "52",
      "dag i vecka": "7",
      "helgdag": "Nyårsdagen",
      "namnsdag": [],
      "flaggdag": "Nyårsdagen"
    },
    {
      "datum": "2017-01-02",
      "veckodag": "Måndag",
      "arbetsfri dag": "Nej",
      "röd dag": "Nej",
      "vecka": "01",
      "dag i vecka": "1",
      "namnsdag": [
        "Svea"
      ],
      "flaggdag": ""
    },
    {
...

Documentation can be found at: https://api.dryg.net

RuntimeError when creating custom class with Dec 31st holiday

>>> from datetime import date
>>> import holidays
>>> 
>>> class TestHolidays(holidays.US):
...     def _populate(self, year):
...         holidays.US._populate(self, year)
...         self[date(year, 12, 31)] = "New Year's Eve"
... 
>>> '2014-12-31' in TestHolidays()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "holidays.py", line 79, in __contains__
    return dict.__contains__(self, self.__keytransform__(key))
  File "holidays.py", line 75, in __keytransform__
    self._populate(year)
  File "<stdin>", line 4, in _populate
  File "holidays.py", line 85, in __setitem__
    return dict.__setitem__(self, self.__keytransform__(key), value)
  File "holidays.py", line 75, in __keytransform__
    self._populate(year)
  File "<stdin>", line 4, in _populate
  File "holidays.py", line 85, in __setitem__
    return dict.__setitem__(self, self.__keytransform__(key), value))
...
  File "holidays.py", line 75, in __keytransform__
    self._populate(year)
  File "<stdin>", line 3, in _populate
  File "holidays.py", line 112, in _populate
    self[date(year, 1, 1)] = name
  File "holidays.py", line 85, in __setitem__
    return dict.__setitem__(self, self.__keytransform__(key), value)
  File "holidays.py", line 72, in __keytransform__
    year = (key + rd(days=+1)).year
RuntimeError: maximum recursion depth exceeded while calling a Python object

Canada Day vs. Dominion Day

You currently report Canada Day as being valid all the way back to 1867, but before 1983, the holiday was called "Dominion Day".

Also, it was not a statutory holiday until 1879, which means there should be no "(Observed)" version of Dominion Day before 1879.

"Bevrijdingsdag" logic for Netherlands not correct

Hi,

The logic for "Bevrijdingsdag" in the Netherlands is not entirely correct:
Related code: https://github.com/ryanss/python-holidays/blob/master/holidays.py#L2015
Related PR: #37

Official government page about this day (in Dutch): https://www.rijksoverheid.nl/onderwerpen/arbeidsovereenkomst-en-cao/vraag-en-antwoord/bevrijdingsdag-5-mei-vrije-dag

Summary: It is an official holiday every year but people do not necessarily get a day off. For a lot of people (but not all) their contract states that they have a day off every 5 years (year % 5) so in those cases the current logic is correct.
Solution: The solution depends on the definition of holiday. If it has to be a day that nobody has to work, then bevrijdingsdag is never a holiday. If it is 'just' an official holiday, bevrijdingsdag is a holiday every year.

I might have time to work on the solution during the weekend.

Cheers,

Aart

Error when combining holiday objects for different provinces

>>> import holidays
>>> bc = holidays.CA(prov='BC')
>>> on = holidays.CA(prov='ON')
>>> bc + on

Traceback (most recent call last):
  File "sum.py", line 4, in <module>
    bc + on
  File "/Users/ryan/Code/holidays.py/holidays.py", line 104, in __add__
    HolidaySum = createHolidaySum(c1, c2)
  File "/Users/ryan/Code/holidays.py/holidays.py", line 115, in createHolidaySum
    class HolidaySum(class1, class2):
TypeError: Error when calling the metaclass bases
    duplicate base class CA

October Bank Holiday in Ireland is wrong

In the code, it should be 10, not 8.
# October Bank Holiday (last Monday in October) if self.country == 'Ireland': name = "October Bank Holiday" self[date(year, 8, 31) + rd(weekday=MO(-1))] = name

How register some strange holidays

Hello,

I am working on Argentina Holidays, and I have an issue.
In addition to 'traditional holidays', we have some holidays named 'Non-work day' for some religions and 'Bridge holidays' or 'tourist holidays'. The last, is not fixed each year. How could I register this holidays?

Regards!

US business days - configurable options

I have reviewed/tested the code to check what exactly it does with US.

My assumption is that the main use for the module is to identify business vs. non-business days. Seems like there might some discrepancies / options at least within US.

The current list seems to reflect US Post Office schedule, though most businesses are likely to follow Bank Holiday schedule (no business if bank is closed - main difference banks closed on Easter).

Moreover, there are some special cases (e.g. "long weekends" with extra Friday on Thanksgiving, etc, early business closing on "pre-holiday" days, like xmas/new year and possibly others).

I wonder if it might be valuable to make things like this configurable beyond the basic USPS schedule?

References -
http://www.theholidayschedule.com/post-office-holidays.php
http://www.theholidayschedule.com/bank-holidays.php
http://www.theholidayschedule.com/nyse-holidays.php

Georgia: Martin Luther King Day

Is it possible that Martin Luther King, Jr. Day is missing for Georgia?

for date,holiday in sorted(holidays.US(state='GA', years=range(2011,2014)).items()):
    print date, holiday
2010-12-31 New Year's Day (Observed)
2011-01-01 New Year's Day
2011-01-17 Robert E. Lee's Birthday
2011-04-25 Confederate Memorial Day
...
2012-01-01 New Year's Day
2012-01-02 New Year's Day (Observed)
2012-04-23 Confederate Memorial Day
...
2012-11-22 Thanksgiving
2012-11-23 Robert E. Lee's Birthday
2012-12-24 Washington's Birthday
2012-12-25 Christmas Day
2013-01-01 New Year's Day
2013-04-22 Confederate Memorial Day
2013-05-27 Memorial Day
...

(For brevity, I replaced some holidays with ... )

The code seems to associate Martin Luther King, Jr. Day with Robert E. Lee's Birthday prior to 2012.

        # Martin Luther King, Jr. Day
        if year >= 1986:
            name = "Martin Luther King, Jr. Day"
            if self.state == 'AL':
                name = "Robert E. Lee/Martin Luther King Birthday"
            elif self.state in ('AS', 'MS'):
                name = ("Dr. Martin Luther King Jr. "
                        "and Robert E. Lee's Birthdays")
            elif self.state in ('AZ', 'NH'):
                name = "Dr. Martin Luther King Jr./Civil Rights Day"
            elif self.state == 'GA' and year < 2012:
                name = "Robert E. Lee's Birthday"
            elif self.state == 'ID' and year >= 2006:
                name = "Martin Luther King, Jr. - Idaho Human Rights Day"
            if self.state != 'GA' or year < 2012:
                self[date(year, 1, 1) + rd(weekday=MO(+3))] = name

However, there are two issues. First, for Martin Luther King, Jr. Day to be included for Georgia after 2012, the last two lines should probably read

            if self.state != 'GA' or year >= 2012:
                self[date(year, 1, 1) + rd(weekday=MO(+3))] = name

Second, it seems that Martin Luther King, Jr. Day has been a state holiday in Georgia already prior to 2012. See https://web.archive.org/web/20110224172609/http://www.georgia.gov/00/channel_modifieddate/0,2096,4802_64437763,00.html, https://web.archive.org/web/20100304032739/http://www.georgia.gov/00/channel_modifieddate/0,2096,4802_64437763,00.html, and https://georgia.gov/popular-topic/observing-state-holidays.

Besides, the above links also seem to suggest that Lincoln's Birthday does not necessarily coincide with Martin Luther King, Jr. Day in Georgia.

Multi-locale support

Hello there!

As long as the library provides verbose human-readable pieces of text (names of holidays), it would make a lot of sense to make that locale-aware. It is especially relevant for countries that have several official languages (like Switzerland, Canada or Belarus).

I see the simplest implementation as adding another parameter to HolidayBase.__init__ as well as the respective get() and its variations.

>>> h = holidays.Canada()
>>>  h.get('2018-09-03')
Labour Day

>>> h.get('2018-09-03', locale='fr_CA')
Fête du travail

Would love to hear if that sounds reasonable...

Thank you!

UK Needs province

Currently the United Kingdom has no province/state member but there are different bank holidays between the countries that make up the UK.

Specifically with E=England, W=Wales, S=Scotland, N=Northern Ireland, R=Republic of Ireland & M=Isle of Man and with all holidays movable to the next working day in the case of not falling on a working day:

  • 1 January (New Year's Day) - EWSNRM
  • 2 January - S
  • 17 March (St Patrick's Day) - NR
  • The Friday before Easter Sunday (Good Friday) - EWSN M
  • The Monday after Easter Sunday (Easter Monday) - EW NRM
  • First Monday in May[2][3] (May Day, Early May Bank Holiday) - EWSNRM
  • Last Monday in May[4][5] (Spring Bank Holiday) - EWSN M
  • First Monday in June (June Bank Holiday) - R
  • First Friday in June (TT Bank Holiday) - M
  • 5 July (Tynwald Day) - M
  • 12 July (The Twelfth, Battle of the Boyne) - N
  • First Monday in August (Summer Bank Holiday) - S R
  • Last Monday in August (Late Summer Bank Holiday, August Bank Holiday) - EW N M
  • Last Monday in October (October Bank Holiday) - R
  • 30 November (St Andrew's Day) - S
  • 25 December (Christmas Day) - EWSNRM
  • 26 December (Boxing Day, St Stephen's Day) - EWSNRM

The really confusing one is that if Christmas day falls on a weekend day it is move to the day after Boxing Day so that if the 25th is Saturday then Boxing Day will be moved from Sunday to Monday and Christmas Day will have a substitute day on the 28th.

Please consider adding these regions with their specific holidays to this tool

Installation error via pip under Python 3.5

Got the following error while trying to install under Python 3.5:

Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-e2vwj6jf-build/setup.py", line 29, in <module>
    long_description=open('README.rst').read(),
  File "/root/miniconda2/envs/keras/lib/python3.5/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5823: ordinal not in range(128)

Thank you for the package, BTW!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.