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

fix: iso week usage #1956

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

fix: iso week usage #1956

wants to merge 2 commits into from

Conversation

JP-Ellis
Copy link

@JP-Ellis JP-Ellis commented Feb 5, 2025

Fava appears to use ISO 8601 weeks (e.g. 2025-W01), but unfortunately does so incorrectly due to a mismatch between ISO 8601 and Gregorian calendar week definitions.

ISO 8601 defines precisely how to handle weeks, namely, that the first week of a year is the week that contains 4 January. This definition results in some occasional mismatches with the Gregorian calendar such as:

  • The first week of 2025 starts on 30 December 2024
  • 3 January 2021 belongs to Week 53 of 2020

Fortunately, the fix is straightforward as strftime provide1:

  • %G for the week-based year
  • %V for the week number of the year (with no 'week 0' as %W can return).

This change will ensure that there is no ambiguity on weeks that straddle the new year, though at the cost of introducing occasional off-by-one errors compared to previously generated data.

Fixes #1805

Footnotes

  1. See POSIX.1-2024

Fava appears to use ISO 8601 weeks (e.g. `2025-W01`), but unfortunately
does so incorrectly due to a mismatch between ISO 8601 and Gregorian
calendar week definitions.

ISO 8601 defines precisely how to handle weeks, namely, that the first
week of a year is the week that contains 4 January. This definition
results in some occasional mismatches with the Gregorian calendar such
as:

- The first week of 2025 starts on 30 December 2024
- 3 January 2021 belongs to Week 53 of 2020

Fortunately, the fix is straightforward as `strftime` provide[^posix]:

- `%G` for the week-based year
- `%V` for the week number of the year (with no 'week 0' as `%W` can
  return).

This change will ensure that there is no ambiguity on weeks that
straddle the new year, though at the cost of introducing occasional
off-by-one errors compared to previously generated data.

[^posix]: See [POSIX.1-2024](https://pubs.opengroup.org/onlinepubs/9799919799/functions/strftime.html)
Signed-off-by: JP-Ellis <[email protected]>
Copy link
Member

@yagebu yagebu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR - this came up in #1805 and I agree with switching to ISO week numbers. The current behaviour is as documented in the help page on the filters and that will have to be updated as well, could you take a look at that? Other than that, the PR looks good

@JP-Ellis
Copy link
Author

JP-Ellis commented Feb 8, 2025

Amazing! Sure happy to look at the docs too. I'll probably do this tomorrow or Monday.

@JP-Ellis
Copy link
Author

JP-Ellis commented Feb 8, 2025

Docs have been updated 👍

Add docs explaining how ISO 8601 week dates are calculated, and give
examples of when they differ slightly from what one might naively expect
looking at a Gregorian calendar.

Signed-off-by: JP-Ellis <[email protected]>
@JP-Ellis
Copy link
Author

Any further updates needed before this can be merged?

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.

Unconsistency in week Date filter
2 participants