Skip to content

Commit af36311

Browse files
committed
Use enums for weekdays and months
Replace strings for weekday and month names with enums Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
1 parent bea7a96 commit af36311

79 files changed

Lines changed: 1452 additions & 1207 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- #147 Use enums for month and weekday names
12
- #146 Use single available language of country as default language
23

34
2026.1.1

docs/how-tos/define-holidays.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,22 @@ The Holidata library provides a set of _date functions_ to handle the different
3636
The `date` function can be used for holidays taking place on a fixed date (_n-th day of a month_), e.g.:
3737

3838
```python
39-
date(month=1, day=1) # January 1st
40-
date(month=12, day=25) # December 25th
39+
date(Month.JANUARY, 1) # January 1st
40+
date(Month.DECEMBER, 25) # December 25th
4141
```
4242

4343
### Weekday Occurrences
4444

4545
For holidays which take place on a certain weekday of a month, there are the functions `first`, `second`, `third`, `fourth`, and `last` to handle those cases, e.g.:
46+
4647
```python
4748
# n-th occurrence of a weekday in a month
48-
first("monday").of("may")
49-
second("tuesday").of("june")
50-
third("wednesday").of("july")
51-
fourth("thursday").of("august")
49+
first(Weekday.MONDAY).of(Month.MAY)
50+
second(Weekday.TUESDAY).of(Month.JUNE)
51+
third(Weekday.WEDNESDAY).of(Month.JULY)
52+
fourth(Weekday.THURSDAY).of(Month.AUGUST)
5253

53-
last("friday").of("september")
54+
last(Weekday.FRIDAY).of(Month.SEPTEMBER)
5455
```
5556

5657
### Easter-Based Dates
@@ -82,14 +83,14 @@ day(2).before(<date_function>) # 2 days before
8283
day(1).after(<date_function>) # 1 day after
8384

8485
# Weekday before/after a date
85-
first("monday").before(<date_function>)
86-
second("tuesday").after(<date_function>)
86+
first(Weekday.MONDAY).before(<date_function>)
87+
second(Weekday.TUESDAY).after(<date_function>)
8788
```
8889

8990
Those calls can be nested. An example for this would be the German holiday _Buß- und Bettag_ which takes place on the 11th day before the first Advent Sunday, which is the fourth sunday before Christmas:
9091

9192
```python
92-
day(11).before(fourth("sunday").before(date(month=12, day=25)))
93+
day(11).before(fourth(Weekday.SUNDAY).before(date(Month.DECEMBER, 25)))
9394
```
9495

9596
### Custom Date Functions

src/holidata/holiday.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def as_dict(self) -> dict:
2626
"date": self.date.strftime("%Y-%m-%d"),
2727
"description": self.description,
2828
"type": self.flags,
29-
"notes": self.notes
29+
"notes": self.notes,
3030
}
3131

3232

src/holidata/holidays/AT/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dateutil.easter import EASTER_WESTERN
22

33
from holidata.holiday import Country
4-
from holidata.utils import day, date
4+
from holidata.utils import day, date, Month
55

66
__all__ = [
77
"AT",
@@ -18,93 +18,93 @@ def __init__(self):
1818

1919
self.define_holiday() \
2020
.with_name("Neujahr") \
21-
.on(date(month=1, day=1)) \
21+
.on(date(Month.JANUARY, 1)) \
2222
.with_flags("NF")
2323

2424
self.define_holiday() \
2525
.with_name("Heilige drei Könige") \
26-
.on(date(month=1, day=6)) \
26+
.on(date(Month.JANUARY, 6)) \
2727
.with_flags("NRF")
2828

2929
self.define_holiday() \
3030
.with_name("Josef") \
3131
.in_regions(["2", "6", "7", "8"]) \
32-
.on(date(month=3, day=19)) \
32+
.on(date(Month.MARCH, 19)) \
3333
.with_flags("RF")
3434

3535
self.define_holiday() \
3636
.with_name("Staatsfeiertag") \
37-
.on(date(month=5, day=1)) \
37+
.on(date(Month.MAY, 1)) \
3838
.with_flags("NF")
3939

4040
self.define_holiday() \
4141
.with_name("Florian") \
4242
.in_regions(["4"]) \
43-
.on(date(month=5, day=4)) \
43+
.on(date(Month.MAY, 4)) \
4444
.with_flags("F")
4545

4646
self.define_holiday() \
4747
.with_name("Mariä Himmelfahrt") \
48-
.on(date(month=8, day=15)) \
48+
.on(date(Month.AUGUST, 15)) \
4949
.with_flags("NRF")
5050

5151
self.define_holiday() \
5252
.with_name("Rupert") \
5353
.in_regions(["5"]) \
54-
.on(date(month=9, day=24)) \
54+
.on(date(Month.SEPTEMBER, 24)) \
5555
.with_flags("F")
5656

5757
self.define_holiday() \
5858
.with_name("Tag der Volksabstimmung") \
5959
.in_regions(["2"]) \
60-
.on(date(month=10, day=10)) \
60+
.on(date(Month.OCTOBER, 10)) \
6161
.with_flags("F")
6262

6363
self.define_holiday() \
6464
.with_name("Nationalfeiertag") \
65-
.on(date(month=10, day=26)) \
65+
.on(date(Month.OCTOBER, 26)) \
6666
.with_flags("NF")
6767

6868
self.define_holiday() \
6969
.with_name("Allerheiligen") \
70-
.on(date(month=11, day=1)) \
70+
.on(date(Month.NOVEMBER, 1)) \
7171
.with_flags("NRF")
7272

7373
self.define_holiday() \
7474
.with_name("Martin") \
7575
.in_regions(["1"]) \
76-
.on(date(month=11, day=11)) \
76+
.on(date(Month.NOVEMBER, 11)) \
7777
.with_flags("F")
7878

7979
self.define_holiday() \
8080
.with_name("Leopold") \
8181
.in_regions(["9", "3"]) \
82-
.on(date(month=11, day=15)) \
82+
.on(date(Month.NOVEMBER, 15)) \
8383
.with_flags("F")
8484

8585
self.define_holiday() \
8686
.with_name("Mariä Empfängnis") \
87-
.on(date(month=12, day=8)) \
87+
.on(date(Month.DECEMBER, 8)) \
8888
.with_flags("NRF")
8989

9090
self.define_holiday() \
9191
.with_name("Heiliger Abend") \
92-
.on(date(month=12, day=24)) \
92+
.on(date(Month.DECEMBER, 24)) \
9393
.with_flags("NRF")
9494

9595
self.define_holiday() \
9696
.with_name("Christtag") \
97-
.on(date(month=12, day=25)) \
97+
.on(date(Month.DECEMBER, 25)) \
9898
.with_flags("NRF")
9999

100100
self.define_holiday() \
101101
.with_name("Stefanitag") \
102-
.on(date(month=12, day=26)) \
102+
.on(date(Month.DECEMBER, 26)) \
103103
.with_flags("NF")
104104

105105
self.define_holiday() \
106106
.with_name("Silvester") \
107-
.on(date(month=12, day=31)) \
107+
.on(date(Month.DECEMBER, 31)) \
108108
.with_flags("NF")
109109

110110
self.define_holiday() \

src/holidata/holidays/AU/ACT.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from holidata.holiday import Region
2-
from holidata.utils import first, second, day, date
2+
from holidata.utils import first, second, day, date, Weekday, Month
33

44

55
class ACT(Region):
@@ -13,14 +13,14 @@ def __init__(self, country):
1313
"""
1414
self.define_holiday() \
1515
.with_name("New Year's Day") \
16-
.on(date(month=1, day=1)) \
16+
.on(date(Month.JANUARY, 1)) \
1717
.with_flags("F")
1818

1919
self.define_holiday() \
2020
.with_name("New Year's Day (observed)") \
21-
.on(first("monday").after(date(month=1, day=1))) \
21+
.on(first(Weekday.MONDAY).after(date(Month.JANUARY, 1))) \
2222
.with_flags("V") \
23-
.on_condition(date(month=1, day=1).is_one_of(["saturday", "sunday"]))
23+
.on_condition(date(Month.JANUARY, 1).is_one_of([Weekday.SATURDAY, Weekday.SUNDAY]))
2424

2525
"""
2626
Australia Day
@@ -29,14 +29,14 @@ def __init__(self, country):
2929
"""
3030
self.define_holiday() \
3131
.with_name("Australia Day") \
32-
.on(date(month=1, day=26)) \
33-
.on_condition(date(month=1, day=26).is_none_of(["saturday", "sunday"])) \
32+
.on(date(Month.JANUARY, 26)) \
33+
.on_condition(date(Month.JANUARY, 26).is_none_of([Weekday.SATURDAY, Weekday.SUNDAY])) \
3434
.with_flags("V")
3535

3636
self.define_holiday() \
3737
.with_name("Australia Day") \
38-
.on(first("monday").after(date(month=1, day=26))) \
39-
.on_condition(date(month=1, day=26).is_one_of(["saturday", "sunday"])) \
38+
.on(first(Weekday.MONDAY).after(date(Month.JANUARY, 26))) \
39+
.on_condition(date(Month.JANUARY, 26).is_one_of([Weekday.SATURDAY, Weekday.SUNDAY])) \
4040
.with_flags("V")
4141

4242
"""
@@ -46,7 +46,7 @@ def __init__(self, country):
4646
"""
4747
self.define_holiday() \
4848
.with_name("Canberra Day") \
49-
.on(second("monday").of("march")) \
49+
.on(second(Weekday.MONDAY).of(Month.MARCH)) \
5050
.with_flags("V")
5151

5252
"""
@@ -92,14 +92,14 @@ def __init__(self, country):
9292
"""
9393
self.define_holiday() \
9494
.with_name("Anzac Day") \
95-
.on(date(month=4, day=25)) \
96-
.on_condition(date(month=4, day=25).is_not_a("sunday")) \
95+
.on(date(Month.APRIL, 25)) \
96+
.on_condition(date(Month.APRIL, 25).is_not_a(Weekday.SUNDAY)) \
9797
.with_flags("V")
9898

9999
self.define_holiday() \
100100
.with_name("Anzac Day") \
101-
.on(first("monday").after(date(month=4, day=25))) \
102-
.on_condition(date(month=4, day=25).is_a("sunday")) \
101+
.on(first(Weekday.MONDAY).after(date(Month.APRIL, 25))) \
102+
.on_condition(date(Month.APRIL, 25).is_a(Weekday.SUNDAY)) \
103103
.with_flags("V")
104104

105105
"""
@@ -109,7 +109,7 @@ def __init__(self, country):
109109
"""
110110
self.define_holiday() \
111111
.with_name("Reconciliation Day") \
112-
.on(first("monday").after(date(month=5, day=26), including=True)) \
112+
.on(first(Weekday.MONDAY).after(date(Month.MAY, 26), including=True)) \
113113
.with_flags("V")
114114

115115
"""
@@ -120,13 +120,13 @@ def __init__(self, country):
120120
self.define_holiday() \
121121
.with_name("Queen's Birthday") \
122122
.until(2022) \
123-
.on(second("monday").of("june")) \
123+
.on(second(Weekday.MONDAY).of(Month.JUNE)) \
124124
.with_flags("V")
125125

126126
self.define_holiday() \
127127
.with_name("King's Birthday") \
128128
.since(2023) \
129-
.on(second("monday").of("june")) \
129+
.on(second(Weekday.MONDAY).of(Month.JUNE)) \
130130
.with_flags("V")
131131

132132
"""
@@ -136,7 +136,7 @@ def __init__(self, country):
136136
"""
137137
self.define_holiday() \
138138
.with_name("Bank Holiday") \
139-
.on(first("monday").of("august")) \
139+
.on(first(Weekday.MONDAY).of(Month.AUGUST)) \
140140
.with_flags("V")
141141

142142
"""
@@ -146,7 +146,7 @@ def __init__(self, country):
146146
"""
147147
self.define_holiday() \
148148
.with_name("Labour Day") \
149-
.on(first("monday").of("october")) \
149+
.on(first(Weekday.MONDAY).of(Month.OCTOBER)) \
150150
.with_flags("V")
151151

152152
"""
@@ -156,20 +156,20 @@ def __init__(self, country):
156156
"""
157157
self.define_holiday() \
158158
.with_name("Christmas Day") \
159-
.on(date(month=12, day=25)) \
159+
.on(date(Month.DECEMBER, 25)) \
160160
.with_flags("RF")
161161

162162
self.define_holiday() \
163163
.with_name("Christmas Day (observed)") \
164-
.on(first("monday").after(date(month=12, day=25))) \
164+
.on(first(Weekday.MONDAY).after(date(Month.DECEMBER, 25))) \
165165
.with_flags("RV") \
166-
.on_condition(date(month=12, day=25).is_a("saturday"))
166+
.on_condition(date(Month.DECEMBER, 25).is_a(Weekday.SATURDAY))
167167

168168
self.define_holiday() \
169169
.with_name("Christmas Day (observed)") \
170-
.on(first("tuesday").after(date(month=12, day=25))) \
170+
.on(first(Weekday.TUESDAY).after(date(Month.DECEMBER, 25))) \
171171
.with_flags("RV") \
172-
.on_condition(date(month=12, day=25).is_a("sunday"))
172+
.on_condition(date(Month.DECEMBER, 25).is_a(Weekday.SUNDAY))
173173

174174
"""
175175
Boxing Day
@@ -178,17 +178,17 @@ def __init__(self, country):
178178
"""
179179
self.define_holiday() \
180180
.with_name("Boxing Day") \
181-
.on(date(month=12, day=26)) \
181+
.on(date(Month.DECEMBER, 26)) \
182182
.with_flags("RF")
183183

184184
self.define_holiday() \
185185
.with_name("Boxing Day (observed)") \
186-
.on(first("monday").after(date(month=12, day=26))) \
186+
.on(first(Weekday.MONDAY).after(date(Month.DECEMBER, 26))) \
187187
.with_flags("RV") \
188-
.on_condition(date(month=12, day=26).is_a("saturday"))
188+
.on_condition(date(Month.DECEMBER, 26).is_a(Weekday.SATURDAY))
189189

190190
self.define_holiday() \
191191
.with_name("Boxing Day (observed)") \
192-
.on(first("tuesday").after(date(month=12, day=26))) \
192+
.on(first(Weekday.TUESDAY).after(date(Month.DECEMBER, 26))) \
193193
.with_flags("RV") \
194-
.on_condition(date(month=12, day=26).is_a("sunday"))
194+
.on_condition(date(Month.DECEMBER, 26).is_a(Weekday.SUNDAY))

0 commit comments

Comments
 (0)