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

Convert NaiveDate::from_weekday_of_month to return Result #1512

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

pitdicker
Copy link
Collaborator

A small PR converting just a single method.

In my personal use I found the way the method currently works inconvenient.

It is not uncommon for scheduling applications to equal some recurring thing on the 5th Weekday of the month with the last Weekday of the month. No matter if that turns out to be the 4th or the 5th Weekday.

Is that practise something we want to support? And if so do we want to adjust this method or add another one?

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.02%. Comparing base (45d22e8) to head (776392a).

Additional details and impacted files
@@           Coverage Diff           @@
##            0.5.x    #1512   +/-   ##
=======================================
  Coverage   94.02%   94.02%           
=======================================
  Files          37       37           
  Lines       16974    16980    +6     
=======================================
+ Hits        15960    15966    +6     
  Misses       1014     1014           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +338 to +341
/// - [`Error::DoesNotExist`] if the specified day does not exist in that month
/// (for example the 5th Monday of Apr. 2023).
/// - [`Error::InvalidArgument`] if the value for `month` or `n` is invalid.
/// - [`Error::OutOfRange`] if `year` is out of range for `NaiveDate`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess these are ordered alphabetically, and I haven't really reviewed for this before, but IMO it would be nice to order these more semantically, roughly in the order they get checked? Like, it feels like InvalidArgument should go first here.

Copy link
Collaborator Author

@pitdicker pitdicker Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not order them alphabetically, but by how often I expect users to encounter them.
DoesNotExist should be quite normal, as it totally depends on the calendar. InvalidArgument shows the input is not checked for correctness before, which I think is less common. OutOfRange is for dates so many thousands of years into the past or future that I think them to be are real edge cases.

Does that sound like a reasonable order?

@djc
Copy link
Contributor

djc commented Mar 13, 2024

It is not uncommon for scheduling applications to equal some recurring thing on the 5th Weekday of the month with the last Weekday of the month. No matter if that turns out to be the 4th or the 5th Weekday.

It feels like that should be a separate method, last_weekday_of_month()?

(I guess an alternative would be to use i == 0 as a sentinel, but that seems generally harder to understand.)

@pitdicker
Copy link
Collaborator Author

i == 5 is the sentinel in common use. 👍 on making it a separate method.

@pitdicker pitdicker merged commit 3265c28 into chronotope:0.5.x Mar 14, 2024
35 checks passed
@pitdicker pitdicker deleted the from_weekday_of_month branch March 14, 2024 12:13
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.

None yet

2 participants