-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
civil: add convenience routines for ISOWeekDate
This PR adds the following methods to `jiff::civil::ISOWeekDate`: * `ISOWeekDate::first_of_week` * `ISOWeekDate::last_of_week` * `ISOWeekDate::first_of_year` * `ISOWeekDate::last_of_year` * `ISOWeekDate::days_in_year` * `ISOWeekDate::weeks_in_year` * `ISOWeekDate::tomorrow` * `ISOWeekDate::yesterday` This makes it a bit easier to navigate around the calendar without having to do this manually. In #227, I originally proposed adding `ISOWeekDate::series` as well, but as I implemented it, I think it turned out to be a bad idea. In particular, `Span` is really a _Gregorian_ period of time, and applying it to `ISOWeekDate` can be awkward. It works fine for units of weeks or lower, but above it's weird. For months, one might excuse it since it's "obvious" that a month will be applied on the Gregorian interpretation of a week date since the ISO 8601 week calendar has no concept of months. But for years... things get weird. If you ask for a series of 1 year intervals starting at `2026-W01-Monday`, then 1 year later is actually `2026-W53-Tuesday` instead of the expected `2027-W01-Monday`. This is because the year arithmetic is done on the Gregorian date and `2026-W01-Monday` is `2025-12-29`. Thus, one year later is `2026-12-29`, which is in turn `2026-W53-Tuesday`. This is just overall begging for bugs. The only way I can see to offer a series-like API for `ISOWeekDate` is to specifically implement ISO week arithmetic. So, I guess we'd return an error for non-zero units of months (thus making the `ISOWeekDate::series` API fallible) and use the ISO week interpretation of "years" instead of the Gregorian interpretation. But this is a fair bit of infrastructure that I'm not sure is worth having. So I've left it out. On the upside, it is very easy to map back and forth between `Date` and `ISOWeekDate`. And you can still use `Date::series` for this, and things will generally make sense as long as you stick to units of weeks or lower. But this does at least make it clear that the series is calculated on the Gregorian calendar and not the ISO 8601 week calendar. Closes #227
- Loading branch information
1 parent
86bff5f
commit d2caefc
Showing
2 changed files
with
339 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters