Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace date parsing with DSL #110

Merged
merged 2 commits into from
Aug 20, 2024
Merged

Replace date parsing with DSL #110

merged 2 commits into from
Aug 20, 2024

Conversation

lauft
Copy link
Member

@lauft lauft commented Aug 19, 2024

Currently dates in holiday definitions are given either by custom functions or strings like

  • fixed dates, e.g. on("01-02") meaning month 1, day 2, i.e. 2nd of January
  • nth weekday, e.g. on("1. monday in August")
  • relative to Easter, e.g. on("3 days before Easter")
  • custom function, eg. on(self.saturday_after_10_31)

Those strings offer no code completion in the IDE and might be error prone (is 3rd of October "10-03" or "03-10"?). Having a DSL for this would help to define those as code, e.g

  • fixed date: on(month=1, day=2)
  • nth weekday: on(first("monday").of("august"))
  • relative to Easter on(day(3).before(self.easter()))
    Especially dates for which custom functions were required can then be defined simply by combining above features, e.g.on(first("saturday").after(month=10, day=31))

This PR adds the functions laid out above and replaces all usages of date strings with the DSL.

Additionally, some refactoring was done to the core classes.

lauft added 2 commits August 19, 2024 20:56
Refactor Region, Country, HolidayGenerator
Optimize emitters, utils
Use @DataClass for 'Holiday'
Add type hints
Replace date parsing with DSL
Replace custom date functions with DSL
Rearrange package structure

Signed-off-by: Thomas Lauf <[email protected]>
@lauft lauft force-pushed the feature/refactorings branch from d5c0fc7 to 628a77f Compare August 20, 2024 21:12
@lauft lauft merged commit d05190c into main Aug 20, 2024
13 checks passed
@lauft lauft deleted the feature/refactorings branch August 20, 2024 21:19
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