Skip to content

Add dates() utility function for explicit year-to-date mappings#151

Merged
lauft merged 1 commit intomainfrom
refactor/dates-method
Feb 19, 2026
Merged

Add dates() utility function for explicit year-to-date mappings#151
lauft merged 1 commit intomainfrom
refactor/dates-method

Conversation

@lauft
Copy link
Member

@lauft lauft commented Feb 19, 2026

Introduce a new dates() function that provides a cleaner way to define holidays with explicit year-to-date mappings, replacing static methods in region classes.

This simplifies holiday definitions by allowing inline date mappings with optional fallback to dynamic date calculations via or_else_on().

Example:

self.define_holiday() \
    .with_name("Grand Final Eve") \
    .since(2019) \
    .on(dates({
        2020: (Month.OCTOBER, 23),  # Adaption due to the COVID-19 pandemic
    }).or_else_on(first(Weekday.FRIDAY).before(last(Weekday.SATURDAY).of(Month.SEPTEMBER)))) \
    .with_flags("V")

Introduce a new dates() function in utils.py that provides a cleaner way to define
holidays with explicit year-to-date mappings, replacing static methods in region classes.

- Add dates() function to utils.py for mapping years to specific dates
- Refactor AU/SA, AU/VIC, AU/WA, ES/CE, ES/ML, SG, and TR regions to use dates()
- Remove redundant static methods for holiday date calculations

This simplifies holiday definitions by allowing inline date mappings with optional
fallback to dynamic date calculations via or_else_on().

Other changes:
- Improve type hinting in HolidayGenerator (date field now accepts None)
- Remove callable validation in on() method for simpler API
- Fix easter_type type hint from str to int in Country class

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
@lauft lauft force-pushed the refactor/dates-method branch from a350883 to 285f63c Compare February 19, 2026 20:45
@lauft lauft merged commit 701ffff into main Feb 19, 2026
11 checks passed
@lauft lauft deleted the refactor/dates-method branch February 19, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant