forked from vacanza/holidays
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholidays.py
More file actions
2227 lines (1860 loc) · 84.3 KB
/
holidays.py
File metadata and controls
2227 lines (1860 loc) · 84.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# python-holidays
# ---------------
# A fast, efficient Python library for generating country, province and state
# specific sets of holidays on the fly. It aims to make determining whether a
# specific date is a holiday as fast and flexible as possible.
#
# Author: ryanss <ryanssdev@icloud.com>
# Website: https://github.com/ryanss/python-holidays
# License: MIT (see LICENSE file)
from datetime import date, datetime
from dateutil.easter import easter
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta as rd
from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU
import six
__version__ = '0.8.1'
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)
WEEKEND = (SATURDAY, SUNDAY)
class HolidayBase(dict):
PROVINCES = []
def __init__(self, years=[], expand=True, observed=True,
prov=None, state=None):
self.observed = observed
self.expand = expand
if isinstance(years, int):
years = [years, ]
self.years = set(years)
if not getattr(self, 'prov', False):
self.prov = prov
self.state = state
for year in list(self.years):
self._populate(year)
def __setattr__(self, key, value):
if key == 'observed' and len(self) > 0:
dict.__setattr__(self, key, value)
if value is True:
# Add (Observed) dates
years = list(self.years)
self.years = set()
self.clear()
for year in years:
self._populate(year)
else:
# Remove (Observed) dates
for k, v in list(self.items()):
if v.find("Observed") >= 0:
del self[k]
else:
return dict.__setattr__(self, key, value)
def __keytransform__(self, key):
if isinstance(key, datetime):
key = key.date()
elif isinstance(key, date):
key = key
elif isinstance(key, int) or isinstance(key, float):
key = datetime.utcfromtimestamp(key).date()
elif isinstance(key, six.string_types):
try:
key = parse(key).date()
except:
raise ValueError("Cannot parse date from string '%s'" % key)
else:
raise TypeError("Cannot convert type '%s' to date." % type(key))
if self.expand and key.year not in self.years:
self.years.add(key.year)
self._populate(key.year)
return key
def __contains__(self, key):
return dict.__contains__(self, self.__keytransform__(key))
def __getitem__(self, key):
return dict.__getitem__(self, self.__keytransform__(key))
def __setitem__(self, key, value):
if key in self:
if self.get(key).find(value) < 0 \
and value.find(self.get(key)) < 0:
value = "%s, %s" % (value, self.get(key))
else:
value = self.get(key)
return dict.__setitem__(self, self.__keytransform__(key), value)
def update(self, *args):
args = list(args)
for arg in args:
if isinstance(arg, dict):
for key, value in list(arg.items()):
self[key] = value
elif isinstance(arg, list):
for item in arg:
self[item] = "Holiday"
else:
self[arg] = "Holiday"
def append(self, *args):
return self.update(*args)
def get(self, key, default=None):
return dict.get(self, self.__keytransform__(key), default)
def get_list(self, key):
return [h for h in self.get(key, "").split(", ") if h]
def pop(self, key, default=None):
if default is None:
return dict.pop(self, self.__keytransform__(key))
return dict.pop(self, self.__keytransform__(key), default)
def __eq__(self, other):
return (dict.__eq__(self, other) and self.__dict__ == other.__dict__)
def __ne__(self, other):
return (dict.__ne__(self, other) or self.__dict__ != other.__dict__)
def __add__(self, other):
if isinstance(other, int) and other == 0:
# Required to sum() list of holidays
# sum([h1, h2]) is equivalent to (0 + h1 + h2)
return self
elif not isinstance(other, HolidayBase):
raise TypeError()
HolidaySum = createHolidaySum(self, other)
country = (getattr(self, 'country', None) or
getattr(other, 'country', None))
if self.country and other.country and self.country != other.country:
c1 = self.country
if not isinstance(c1, list):
c1 = [c1]
c2 = other.country
if not isinstance(c2, list):
c2 = [c2]
country = c1 + c2
prov = getattr(self, 'prov', None) or getattr(other, 'prov', None)
if self.prov and other.prov and self.prov != other.prov:
p1 = self.prov if isinstance(self.prov, list) else [self.prov]
p2 = other.prov if isinstance(other.prov, list) else [other.prov]
prov = p1 + p2
return HolidaySum(years=(self.years | other.years),
expand=(self.expand or other.expand),
observed=(self.observed or other.observed),
country=country, prov=prov)
def __radd__(self, other):
return self.__add__(other)
def _populate(self, year):
pass
def createHolidaySum(h1, h2):
class HolidaySum(HolidayBase):
def __init__(self, country, **kwargs):
self.country = country
self.holidays = []
if getattr(h1, 'holidays', False):
for h in h1.holidays:
self.holidays.append(h)
else:
self.holidays.append(h1)
if getattr(h2, 'holidays', False):
for h in h2.holidays:
self.holidays.append(h)
else:
self.holidays.append(h2)
HolidayBase.__init__(self, **kwargs)
def _populate(self, year):
for h in self.holidays[::-1]:
h._populate(year)
self.update(h)
return HolidaySum
class Canada(HolidayBase):
PROVINCES = ['AB', 'BC', 'MB', 'NB', 'NL', 'NS', 'NT', 'NU', 'ON', 'PE',
'QC', 'SK', 'YU']
def __init__(self, **kwargs):
self.country = 'CA'
self.prov = kwargs.pop('prov', 'ON')
HolidayBase.__init__(self, **kwargs)
def _populate(self, year):
# New Year's Day
if year >= 1867:
name = "New Year's Day"
self[date(year, 1, 1)] = name
if self.observed and date(year, 1, 1).weekday() == 6:
self[date(year, 1, 1) + rd(days=+1)] = name + " (Observed)"
elif self.observed and date(year, 1, 1).weekday() == 5:
# Add Dec 31st from the previous year without triggering
# the entire year to be added
expand = self.expand
self.expand = False
self[date(year, 1, 1) + rd(days=-1)] = name + " (Observed)"
self.expand = expand
# The next year's observed New Year's Day can be in this year
# when it falls on a Friday (Jan 1st is a Saturday)
if self.observed and date(year, 12, 31).weekday() == 4:
self[date(year, 12, 31)] = name + " (Observed)"
# Family Day / Louis Riel Day (MB) / Islander Day (PE)
# / Heritage Day (NS, YU)
if self.prov in ('AB', 'SK', 'ON') and year >= 2008:
self[date(year, 2, 1) + rd(weekday=MO(+3))] = "Family Day"
elif self.prov in ('AB', 'SK') and year >= 2007:
self[date(year, 2, 1) + rd(weekday=MO(+3))] = "Family Day"
elif self.prov == 'AB' and year >= 1990:
self[date(year, 2, 1) + rd(weekday=MO(+3))] = "Family Day"
elif self.prov == 'BC' and year >= 2013:
self[date(year, 2, 1) + rd(weekday=MO(+2))] = "Family Day"
elif self.prov == 'MB' and year >= 2008:
self[date(year, 2, 1) + rd(weekday=MO(+3))] = "Louis Riel Day"
elif self.prov == 'PE' and year >= 2010:
self[date(year, 2, 1) + rd(weekday=MO(+3))] = "Islander Day"
elif self.prov == 'PE' and year == 2009:
self[date(year, 2, 1) + rd(weekday=MO(+2))] = "Islander Day"
elif self.prov in ('NS') and year >= 2015:
# http://novascotia.ca/lae/employmentrights/NovaScotiaHeritageDay.asp
self[date(year, 2, 1) + rd(weekday=MO(+3))] = "Heritage Day"
elif self.prov in ('YU'):
# start date?
# http://heritageyukon.ca/programs/heritage-day
# https://en.wikipedia.org/wiki/Family_Day_(Canada)#Yukon_Heritage_Day
# Friday before the last Sunday in February
dt = date(year, 3, 1) + rd(weekday=SU(-1)) + rd(weekday=FR(-1))
self[dt] = "Heritage Day"
# St. Patrick's Day
if self.prov == 'NL' and year >= 1900:
dt = date(year, 3, 17)
# Nearest Monday to March 17
dt1 = date(year, 3, 17) + rd(weekday=MO(-1))
dt2 = date(year, 3, 17) + rd(weekday=MO(+1))
if dt2 - dt <= dt - dt1:
self[dt2] = "St. Patrick's Day"
else:
self[dt1] = "St. Patrick's Day"
# Good Friday
if self.prov != 'QC' and year >= 1867:
self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"
# Easter Monday
if self.prov == 'QC' and year >= 1867:
self[easter(year) + rd(weekday=MO)] = "Easter Monday"
# St. George's Day
if self.prov == 'NL' and year == 2010:
# 4/26 is the Monday closer to 4/23 in 2010
# but the holiday was observed on 4/19? Crazy Newfies!
self[date(2010, 4, 19)] = "St. George's Day"
elif self.prov == 'NL' and year >= 1990:
dt = date(year, 4, 23)
# Nearest Monday to April 23
dt1 = dt + rd(weekday=MO(-1))
dt2 = dt + rd(weekday=MO(+1))
if dt2 - dt < dt - dt1:
self[dt2] = "St. George's Day"
else:
self[dt1] = "St. George's Day"
# Victoria Day / National Patriotes Day (QC)
if self.prov not in ('NB', 'NS', 'PE', 'NL', 'QC') and year >= 1953:
self[date(year, 5, 24) + rd(weekday=MO(-1))] = "Victoria Day"
elif self.prov == 'QC' and year >= 1953:
name = "National Patriotes Day"
self[date(year, 5, 24) + rd(weekday=MO(-1))] = name
# National Aboriginal Day
if self.prov == 'NT' and year >= 1996:
self[date(year, 6, 21)] = "National Aboriginal Day"
# St. Jean Baptiste Day
if self.prov == 'QC' and year >= 1925:
self[date(year, 6, 24)] = "St. Jean Baptiste Day"
if self.observed and date(year, 6, 24).weekday() == 6:
self[date(year, 6, 25)] = "St. Jean Baptiste Day (Observed)"
# Discovery Day
if self.prov == 'NL' and year >= 1997:
dt = date(year, 6, 24)
# Nearest Monday to June 24
dt1 = dt + rd(weekday=MO(-1))
dt2 = dt + rd(weekday=MO(+1))
if dt2 - dt <= dt - dt1:
self[dt2] = "Discovery Day"
else:
self[dt1] = "Discovery Day"
elif self.prov == 'YU' and year >= 1912:
self[date(year, 8, 1) + rd(weekday=MO(+3))] = "Discovery Day"
# Canada Day / Memorial Day (NL)
if self.prov != 'NL' and year >= 1867:
name = "Canada Day"
self[date(year, 7, 1)] = name
if self.observed and date(year, 7, 1).weekday() in (5, 6):
self[date(year, 7, 1) + rd(weekday=MO)] = name + " (Observed)"
elif year >= 1867:
name = "Memorial Day"
self[date(year, 7, 1)] = name
if self.observed and date(year, 7, 1).weekday() in (5, 6):
self[date(year, 7, 1) + rd(weekday=MO)] = name + " (Observed)"
# Nunavut Day
if self.prov == 'NU' and year >= 2001:
self[date(year, 7, 9)] = "Nunavut Day"
if self.observed and date(year, 7, 9).weekday() == 6:
self[date(year, 7, 10)] = "Nunavut Day (Observed)"
elif self.prov == 'NU' and year == 2000:
self[date(2000, 4, 1)] = "Nunavut Day"
# Civic Holiday
if self.prov in ('ON', 'MB', 'NT') and year >= 1900:
self[date(year, 8, 1) + rd(weekday=MO)] = "Civic Holiday"
elif self.prov in ('AB') and year >= 1974:
# https://en.wikipedia.org/wiki/Civic_Holiday#Alberta
self[date(year, 8, 1) + rd(weekday=MO)] = "Heritage Day"
elif self.prov in ('BC') and year >= 1974:
# https://en.wikipedia.org/wiki/Civic_Holiday
self[date(year, 8, 1) + rd(weekday=MO)] = "British Columbia Day"
elif self.prov in ('NB') and year >= 1900:
# https://en.wikipedia.org/wiki/Civic_Holiday
self[date(year, 8, 1) + rd(weekday=MO)] = "New Brunswick Day"
elif self.prov in ('SK') and year >= 1900:
# https://en.wikipedia.org/wiki/Civic_Holiday
self[date(year, 8, 1) + rd(weekday=MO)] = "Saskatchewan Day"
# Labour Day
if year >= 1894:
self[date(year, 9, 1) + rd(weekday=MO)] = "Labour Day"
# Thanksgiving
if self.prov not in ('NB', 'NS', 'PE', 'NL') and year >= 1931:
if year == 1935:
# in 1935, Canadian Thanksgiving was moved due to the General
# Election falling on the second Monday of October
# https://books.google.ca/books?id=KcwlQsmheG4C&pg=RA1-PA1940&lpg=RA1-PA1940&dq=canada+thanksgiving+1935&source=bl&ots=j4qYrcfGuY&sig=gxXeAQfXVsOF9fOwjSMswPHJPpM&hl=en&sa=X&ved=0ahUKEwjO0f3J2PjOAhVS4mMKHRzKBLAQ6AEIRDAG#v=onepage&q=canada%20thanksgiving%201935&f=false
self[date(1935, 10, 25)] = "Thanksgiving"
else:
self[date(year, 10, 1) + rd(weekday=MO(+2))] = "Thanksgiving"
# Remembrance Day
name = "Remembrance Day"
provinces = ('ON', 'QC', 'NS', 'NL', 'NT', 'PE', 'SK')
if self.prov not in provinces and year >= 1931:
self[date(year, 11, 11)] = name
elif self.prov in ('NS', 'NL', 'NT', 'PE', 'SK') and year >= 1931:
self[date(year, 11, 11)] = name
if self.observed and date(year, 11, 11).weekday() == 6:
name = name + " (Observed)"
self[date(year, 11, 11) + rd(weekday=MO)] = name
# Christmas Day
if year >= 1867:
self[date(year, 12, 25)] = "Christmas Day"
if self.observed and date(year, 12, 25).weekday() == 5:
self[date(year, 12, 24)] = "Christmas Day (Observed)"
elif self.observed and date(year, 12, 25).weekday() == 6:
self[date(year, 12, 26)] = "Christmas Day (Observed)"
# Boxing Day
if year >= 1867:
name = "Boxing Day"
name_observed = name + " (Observed)"
if self.observed and date(year, 12, 26).weekday() in (5, 6):
self[date(year, 12, 26) + rd(weekday=MO)] = name_observed
elif self.observed and date(year, 12, 26).weekday() == 0:
self[date(year, 12, 27)] = name_observed
else:
self[date(year, 12, 26)] = name
class CA(Canada):
pass
class Colombia(HolidayBase):
# https://es.wikipedia.org/wiki/Anexo:D%C3%ADas_festivos_en_Colombia
def __init__(self, **kwargs):
self.country = 'CO'
HolidayBase.__init__(self, **kwargs)
def _populate(self, year):
# Fixed date holidays!
# If observed=True and they fall on a weekend they are not observed.
# If observed=False there are 18 holidays
# New Year's Day
if self.observed and date(year, 1, 1).weekday() in WEEKEND:
pass
else:
self[date(year, 1, 1)] = "Año Nuevo [New Year's Day]"
# Labor Day
self[date(year, 5, 1)] = "Día del Trabajo [Labour Day]"
# Independence Day
name = "Día de la Independencia [Independence Day]"
if self.observed and date(year, 7, 20).weekday() in WEEKEND:
pass
else:
self[date(year, 7, 20)] = name
# Battle of Boyaca
self[date(year, 8, 7)] = "Batalla de Boyacá [Battle of Boyacá]"
# Immaculate Conception
if self.observed and date(year, 12, 8).weekday() in WEEKEND:
pass
else:
self[date(year, 12, 8)
] = "La Inmaculada Concepción [Immaculate Conception]"
# Christmas
self[date(year, 12, 25)] = "Navidad [Christmas]"
# Emiliani Law holidays!
# Unless they fall on a Monday they are observed the following monday
# Epiphany
name = "Día de los Reyes Magos [Epiphany]"
if date(year, 1, 6).weekday() == 0 or not self.observed:
self[date(year, 1, 6)] = name
else:
self[date(year, 1, 6) + rd(weekday=MO)] = name + "(Observed)"
# Saint Joseph's Day
name = "Día de San José [Saint Joseph's Day]"
if date(year, 3, 19).weekday() == 0 or not self.observed:
self[date(year, 3, 19)] = name
else:
self[date(year, 3, 19) + rd(weekday=MO)] = name + "(Observed)"
# Saint Peter and Saint Paul's Day
name = "San Pedro y San Pablo [Saint Peter and Saint Paul]"
if date(year, 6, 29).weekday() == 0 or not self.observed:
self[date(year, 6, 29)] = name
else:
self[date(year, 6, 29) + rd(weekday=MO)] = name + "(Observed)"
# Assumption of Mary
name = "La Asunción [Assumption of Mary]"
if date(year, 8, 15).weekday() == 0 or not self.observed:
self[date(year, 8, 15)] = name
else:
self[date(year, 8, 15) + rd(weekday=MO)] = name + "(Observed)"
# Discovery of America
name = "Descubrimiento de América [Discovery of America]"
if date(year, 10, 12).weekday() == 0 or not self.observed:
self[date(year, 10, 12)] = name
else:
self[date(year, 10, 12) + rd(weekday=MO)] = name + "(Observed)"
# All Saints’ Day
name = "Dia de Todos los Santos [All Saint's Day]"
if date(year, 11, 1).weekday() == 0 or not self.observed:
self[date(year, 11, 1)] = name
else:
self[date(year, 11, 1) + rd(weekday=MO)] = name + "(Observed)"
# Independence of Cartagena
name = "Independencia de Cartagena [Independence of Cartagena]"
if date(year, 11, 11).weekday() == 0 or not self.observed:
self[date(year, 11, 11)] = name
else:
self[date(year, 11, 11) + rd(weekday=MO)] = name + "(Observed)"
# Holidays based on Easter
# Maundy Thursday
self[easter(year) + rd(weekday=TH(-1))
] = "Jueves Santo [Maundy Thursday]"
# Good Friday
self[easter(year) + rd(weekday=FR(-1))
] = "Viernes Santo [Good Friday]"
# Holidays based on Easter but are observed the following monday
# (unless they occur on a monday)
# Ascension of Jesus
name = "Ascensión del señor [Ascension of Jesus]"
hdate = easter(year) + rd(days=+39)
if hdate.weekday() == 0 or not self.observed:
self[hdate] = name
else:
self[hdate + rd(weekday=MO)] = name + "(Observed)"
# Corpus Christi
name = "Corpus Christi [Corpus Christi]"
hdate = easter(year) + rd(days=+60)
if hdate.weekday() == 0 or not self.observed:
self[hdate] = name
else:
self[hdate + rd(weekday=MO)] = name + "(Observed)"
# Sacred Heart
name = "Sagrado Corazón [Sacred Heart]"
hdate = easter(year) + rd(days=+68)
if hdate.weekday() == 0 or not self.observed:
self[hdate] = name
else:
self[hdate + rd(weekday=MO)] = name + "(Observed)"
class CO(Colombia):
pass
class Mexico(HolidayBase):
def __init__(self, **kwargs):
self.country = 'MX'
HolidayBase.__init__(self, **kwargs)
def _populate(self, year):
# New Year's Day
name = "Año Nuevo [New Year's Day]"
self[date(year, 1, 1)] = name
if self.observed and date(year, 1, 1).weekday() == 6:
self[date(year, 1, 1) + rd(days=+1)] = name + " (Observed)"
elif self.observed and date(year, 1, 1).weekday() == 5:
# Add Dec 31st from the previous year without triggering
# the entire year to be added
expand = self.expand
self.expand = False
self[date(year, 1, 1) + rd(days=-1)] = name + " (Observed)"
self.expand = expand
# The next year's observed New Year's Day can be in this year
# when it falls on a Friday (Jan 1st is a Saturday)
if self.observed and date(year, 12, 31).weekday() == 4:
self[date(year, 12, 31)] = name + " (Observed)"
# Constitution Day
name = "Día de la Constitución [Constitution Day]"
if 2006 >= year >= 1917:
self[date(year, 2, 5)] = name
elif year >= 2007:
self[date(year, 2, 1) + rd(weekday=MO(+1))] = name
# Benito Juárez's birthday
name = "Natalicio de Benito Juárez [Benito Juárez's birthday]"
if 2006 >= year >= 1917:
self[date(year, 3, 21)] = name
elif year >= 2007:
self[date(year, 3, 1) + rd(weekday=MO(+3))] = name
# Labor Day
if year >= 1923:
self[date(year, 5, 1)] = "Día del Trabajo [Labour Day]"
if self.observed and date(year, 5, 1).weekday() == 5:
self[date(year, 5, 1) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 5, 1).weekday() == 6:
self[date(year, 5, 1) + rd(days=+1)] = name + " (Observed)"
# Independence Day
name = "Día de la Independencia [Independence Day]"
self[date(year, 9, 16)] = name
if self.observed and date(year, 9, 16).weekday() == 5:
self[date(year, 9, 16) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 9, 16).weekday() == 6:
self[date(year, 9, 16) + rd(days=+1)] = name + " (Observed)"
# Revolution Day
name = "Día de la Revolución [Revolution Day]"
if 2006 >= year >= 1917:
self[date(year, 11, 20)] = name
elif year >= 2007:
self[date(year, 11, 1) + rd(weekday=MO(+3))] = name
# Change of Federal Government
# Every six years--next observance 2018
name = "Transmisión del Poder Ejecutivo Federal"
name += " [Change of Federal Government]"
if (2018 - year) % 6 == 0:
self[date(year, 12, 1)] = name
if self.observed and date(year, 12, 1).weekday() == 5:
self[date(year, 12, 1) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 12, 1).weekday() == 6:
self[date(year, 12, 1) + rd(days=+1)] = name + " (Observed)"
# Christmas
self[date(year, 12, 25)] = "Navidad [Christmas]"
if self.observed and date(year, 12, 25).weekday() == 5:
self[date(year, 12, 25) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 12, 25).weekday() == 6:
self[date(year, 12, 25) + rd(days=+1)] = name + " (Observed)"
class MX(Mexico):
pass
class UnitedStates(HolidayBase):
# https://en.wikipedia.org/wiki/Public_holidays_in_the_United_States
STATES = ['AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL',
'GA', 'GU', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME',
'MD', 'MH', 'MA', 'MI', 'FM', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV',
'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR', 'PW',
'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'VI',
'WA', 'WV', 'WI', 'WY']
def __init__(self, **kwargs):
self.country = 'US'
HolidayBase.__init__(self, **kwargs)
def _populate(self, year):
# New Year's Day
if year > 1870:
name = "New Year's Day"
self[date(year, 1, 1)] = name
if self.observed and date(year, 1, 1).weekday() == 6:
self[date(year, 1, 1) + rd(days=+1)] = name + " (Observed)"
elif self.observed and date(year, 1, 1).weekday() == 5:
# Add Dec 31st from the previous year without triggering
# the entire year to be added
expand = self.expand
self.expand = False
self[date(year, 1, 1) + rd(days=-1)] = name + " (Observed)"
self.expand = expand
# The next year's observed New Year's Day can be in this year
# when it falls on a Friday (Jan 1st is a Saturday)
if self.observed and date(year, 12, 31).weekday() == 4:
self[date(year, 12, 31)] = name + " (Observed)"
# Epiphany
if self.state == 'PR':
self[date(year, 1, 6)] = "Epiphany"
# Three King's Day
if self.state == 'VI':
self[date(year, 1, 6)] = "Three King's Day"
# Lee Jackson Day
name = "Lee Jackson Day"
if self.state == 'VA' and year >= 2000:
dt = date(year, 1, 1) + rd(weekday=MO(+3)) + rd(weekday=FR(-1))
self[dt] = name
elif self.state == 'VA' and year >= 1983:
self[date(year, 1, 1) + rd(weekday=MO(+3))] = name
elif self.state == 'VA' and year >= 1889:
self[date(year, 1, 19)] = name
# Inauguration Day
if self.state in ('DC', 'LA', 'MD', 'VA') and year >= 1789:
name = "Inauguration Day"
if (year - 1789) % 4 == 0 and year >= 1937:
self[date(year, 1, 20)] = name
if date(year, 1, 20).weekday() == 6:
self[date(year, 1, 21)] = name + " (Observed)"
elif (year - 1789) % 4 == 0:
self[date(year, 3, 4)] = name
if date(year, 3, 4).weekday() == 6:
self[date(year, 3, 5)] = name + " (Observed)"
# 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"
self[date(year, 1, 1) + rd(weekday=MO(+3))] = name
# Lincoln's Birthday
name = "Lincoln's Birthday"
if (self.state in ('CT', 'IL', 'IA', 'NJ', 'NY') and year >= 1971) \
or (self.state == 'CA' and year >= 1971 and year <= 2009):
self[date(year, 2, 12)] = name
if self.observed and date(year, 2, 12).weekday() == 5:
self[date(year, 2, 11)] = name + " (Observed)"
elif self.observed and date(year, 2, 12).weekday() == 6:
self[date(year, 2, 13)] = name + " (Observed)"
# Susan B. Anthony Day
if (self.state == 'CA' and year >= 2014) \
or (self.state == 'FL' and year >= 2011) \
or (self.state == 'NY' and year >= 2004) \
or (self.state == 'WI' and year >= 1976):
self[date(year, 2, 15)] = "Susan B. Anthony Day"
# Washington's Birthday
name = "Washington's Birthday"
if self.state == 'AL':
name = "George Washington/Thomas Jefferson Birthday"
elif self.state == 'AS':
name = "George Washington's Birthday and Daisy Gatson Bates Day"
elif self.state in ('PR', 'VI'):
name = "Presidents' Day"
if self.state not in ('DE', 'FL', 'GA', 'NM', 'PR'):
if year > 1970:
self[date(year, 2, 1) + rd(weekday=MO(+3))] = name
elif year >= 1879:
self[date(year, 2, 22)] = name
elif self.state == 'GA':
if date(year, 12, 24).weekday() != 2:
self[date(year, 12, 24)] = name
else:
self[date(year, 12, 26)] = name
elif self.state in ('PR', 'VI'):
self[date(year, 2, 1) + rd(weekday=MO(+3))] = name
# Mardi Gras
if self.state == 'LA' and year >= 1857:
self[easter(year) + rd(days=-47)] = "Mardi Gras"
# Guam Discovery Day
if self.state == 'GU' and year >= 1970:
self[date(year, 3, 1) + rd(weekday=MO)] = "Guam Discovery Day"
# Casimir Pulaski Day
if self.state == 'IL' and year >= 1978:
self[date(year, 3, 1) + rd(weekday=MO)] = "Casimir Pulaski Day"
# Texas Independence Day
if self.state == 'TX' and year >= 1874:
self[date(year, 3, 2)] = "Texas Independence Day"
# Town Meeting Day
if self.state == 'VT' and year >= 1800:
self[date(year, 3, 1) + rd(weekday=TU)] = "Town Meeting Day"
# Evacuation Day
if self.state == 'MA' and year >= 1901:
name = "Evacuation Day"
self[date(year, 3, 17)] = name
if date(year, 3, 17).weekday() in (5, 6):
self[date(year, 3, 17) + rd(weekday=MO)] = name + " (Observed)"
# Emancipation Day
if self.state == 'PR':
self[date(year, 3, 22)] = "Emancipation Day"
if self.observed and date(year, 3, 22).weekday() == 6:
self[date(year, 3, 23)] = "Emancipation Day (Observed)"
# Prince Jonah Kuhio Kalanianaole Day
if self.state == 'HI' and year >= 1949:
name = "Prince Jonah Kuhio Kalanianaole Day"
self[date(year, 3, 26)] = name
if self.observed and date(year, 3, 26).weekday() == 5:
self[date(year, 3, 25)] = name + " (Observed)"
elif self.observed and date(year, 3, 26).weekday() == 6:
self[date(year, 3, 27)] = name + " (Observed)"
# Steward's Day
name = "Steward's Day"
if self.state == 'AK' and year >= 1955:
self[date(year, 4, 1) + rd(days=-1, weekday=MO(-1))] = name
elif self.state == 'AK' and year >= 1918:
self[date(year, 3, 30)] = name
# César Chávez Day
name = "César Chávez Day"
if self.state == 'CA' and year >= 1995:
self[date(year, 3, 31)] = name
if self.observed and date(year, 3, 31).weekday() == 6:
self[date(year, 4, 1)] = name + " (Observed)"
elif self.state == 'TX' and year >= 2000:
self[date(year, 3, 31)] = name
# Transfer Day
if self.state == 'VI':
self[date(year, 3, 31)] = "Transfer Day"
# Emancipation Day
if self.state == 'DC' and year >= 2005:
name = "Emancipation Day"
self[date(year, 4, 16)] = name
if self.observed and date(year, 4, 16).weekday() == 5:
self[date(year, 4, 15)] = name + " (Observed)"
elif self.observed and date(year, 4, 16).weekday() == 6:
self[date(year, 4, 17)] = name + " (Observed)"
# Patriots' Day
if self.state in ('ME', 'MA') and year >= 1969:
self[date(year, 4, 1) + rd(weekday=MO(+3))] = "Patriots' Day"
elif self.state in ('ME', 'MA') and year >= 1894:
self[date(year, 4, 19)] = "Patriots' Day"
# Holy Thursday
if self.state == 'VI':
self[easter(year) + rd(weekday=TH(-1))] = "Holy Thursday"
# Good Friday
if self.state in ('CT', 'DE', 'GU', 'IN', 'KY', 'LA',
'NJ', 'NC', 'PR', 'TN', 'TX', 'VI'):
self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"
# Easter Monday
if self.state == 'VI':
self[easter(year) + rd(weekday=MO)] = "Easter Monday"
# Confederate Memorial Day
name = "Confederate Memorial Day"
if self.state in ('AL', 'GA', 'MS', 'SC') and year >= 1866:
if self.state == 'GA' and year >= 2016:
name = "State Holiday"
self[date(year, 4, 1) + rd(weekday=MO(+4))] = name
elif self.state == 'TX' and year >= 1931:
self[date(year, 1, 19)] = name
# San Jacinto Day
if self.state == 'TX' and year >= 1875:
self[date(year, 4, 21)] = "San Jacinto Day"
# Arbor Day
if self.state == 'NE' and year >= 1989:
self[date(year, 4, 30) + rd(weekday=FR(-1))] = "Arbor Day"
elif self.state == 'NE' and year >= 1875:
self[date(year, 4, 22)] = "Arbor Day"
# Primary Election Day
if self.state == 'IN' and \
((year >= 2006 and year % 2 == 0) or year >= 2015):
dt = date(year, 5, 1) + rd(weekday=MO)
self[dt + rd(days=+1)] = "Primary Election Day"
# Truman Day
if self.state == 'MO' and year >= 1949:
name = "Truman Day"
self[date(year, 5, 8)] = name
if self.observed and date(year, 5, 8).weekday() == 5:
self[date(year, 5, 7)] = name + " (Observed)"
elif self.observed and date(year, 5, 8).weekday() == 6:
self[date(year, 5, 10)] = name + " (Observed)"
# Memorial Day
if year > 1970:
self[date(year, 5, 31) + rd(weekday=MO(-1))] = "Memorial Day"
elif year >= 1888:
self[date(year, 5, 30)] = "Memorial Day"
# Jefferson Davis Birthday
name = "Jefferson Davis Birthday"
if self.state == 'AL' and year >= 1890:
self[date(year, 6, 1) + rd(weekday=MO)] = name
# Kamehameha Day
if self.state == 'HI' and year >= 1872:
self[date(year, 6, 11)] = "Kamehameha Day"
if self.observed and year >= 2011:
if date(year, 6, 11).weekday() == 5:
self[date(year, 6, 10)] = "Kamehameha Day (Observed)"
elif date(year, 6, 11).weekday() == 6:
self[date(year, 6, 12)] = "Kamehameha Day (Observed)"
# Emancipation Day In Texas
if self.state == 'TX' and year >= 1980:
self[date(year, 6, 19)] = "Emancipation Day In Texas"
# West Virginia Day
name = "West Virginia Day"
if self.state == 'WV' and year >= 1927:
self[date(year, 6, 20)] = name
if self.observed and date(year, 6, 20).weekday() == 5:
self[date(year, 6, 19)] = name + " (Observed)"
elif self.observed and date(year, 6, 20).weekday() == 6:
self[date(year, 6, 21)] = name + " (Observed)"
# Emancipation Day in US Virgin Islands
if self.state == 'VI':
self[date(year, 7, 3)] = "Emancipation Day"
# Independence Day
if year > 1870:
name = "Independence Day"
self[date(year, 7, 4)] = name
if self.observed and date(year, 7, 4).weekday() == 5:
self[date(year, 7, 4) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 7, 4).weekday() == 6:
self[date(year, 7, 4) + rd(days=+1)] = name + " (Observed)"
# Liberation Day (Guam)
if self.state == 'GU' and year >= 1945:
self[date(year, 7, 21)] = "Liberation Day (Guam)"
# Pioneer Day
if self.state == 'UT' and year >= 1849:
name = "Pioneer Day"
self[date(year, 7, 24)] = name
if self.observed and date(year, 7, 24).weekday() == 5:
self[date(year, 7, 24) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 7, 24).weekday() == 6:
self[date(year, 7, 24) + rd(days=+1)] = name + " (Observed)"
# Constitution Day
if self.state == 'PR':
self[date(year, 7, 25)] = "Constitution Day"
if self.observed and date(year, 7, 25).weekday() == 6:
self[date(year, 7, 26)] = "Constitution Day (Observed)"
# Victory Day
if self.state == 'RI' and year >= 1948:
self[date(year, 8, 1) + rd(weekday=MO(+2))] = "Victory Day"
# Statehood Day (Hawaii)
if self.state == 'HI' and year >= 1959:
self[date(year, 8, 1) + rd(weekday=FR(+3))] = "Statehood Day"
# Bennington Battle Day
if self.state == 'VT' and year >= 1778:
name = "Bennington Battle Day"
self[date(year, 8, 16)] = name
if self.observed and date(year, 8, 16).weekday() == 5:
self[date(year, 8, 15)] = name + " (Observed)"
elif self.observed and date(year, 8, 16).weekday() == 6:
self[date(year, 8, 17)] = name + " (Observed)"
# Lyndon Baines Johnson Day
if self.state == 'TX' and year >= 1973:
self[date(year, 8, 27)] = "Lyndon Baines Johnson Day"
# Labor Day
if year >= 1894:
self[date(year, 9, 1) + rd(weekday=MO)] = "Labor Day"
# Columbus Day
if self.state not in ('AK', 'DE', 'FL', 'HI', 'NV'):
if self.state == 'SD':
name = "Native American Day"
elif self.state == 'VI':
name = "Columbus Day and Puerto Rico Friendship Day"
else:
name = "Columbus Day"
if year >= 1970:
self[date(year, 10, 1) + rd(weekday=MO(+2))] = name
elif year >= 1937:
self[date(year, 10, 12)] = name
# Alaska Day
if self.state == 'AK' and year >= 1867:
self[date(year, 10, 18)] = "Alaska Day"
if self.observed and date(year, 10, 18).weekday() == 5:
self[date(year, 10, 18) + rd(days=-1)] = name + " (Observed)"
elif self.observed and date(year, 10, 18).weekday() == 6:
self[date(year, 10, 18) + rd(days=+1)] = name + " (Observed)"
# Nevada Day
if self.state == 'NV' and year >= 1933:
dt = date(year, 10, 31)
if year >= 2000:
dt += rd(weekday=FR(-1))
self[dt] = "Nevada Day"
if self.observed and dt.weekday() == 5:
self[dt + rd(days=-1)] = "Nevada Day (Observed)"
elif self.observed and dt.weekday() == 6:
self[dt + rd(days=+1)] = "Nevada Day (Observed)"
# Liberty Day
if self.state == 'VI':
self[date(year, 11, 1)] = "Liberty Day"
# Election Day
if (self.state in ('DE', 'HI', 'IL', 'IN', 'LA',
'MT', 'NH', 'NJ', 'NY', 'WV') and
year >= 2008 and year % 2 == 0) \
or (self.state in ('IN', 'NY') and year >= 2015):
dt = date(year, 11, 1) + rd(weekday=MO)
self[dt + rd(days=+1)] = "Election Day"
# All Souls' Day
if self.state == 'GU':
self[date(year, 11, 2)] = "All Souls' Day"
# Veterans Day
if year > 1953:
name = "Veterans Day"
else:
name = "Armistice Day"
if 1978 > year > 1970:
self[date(year, 10, 1) + rd(weekday=MO(+4))] = name
elif year >= 1938: