diff --git a/src/fava/help/filters.md b/src/fava/help/filters.md index 95ab453cc..b86c9adcb 100644 --- a/src/fava/help/filters.md +++ b/src/fava/help/filters.md @@ -20,6 +20,10 @@ current year up to today, or `year-1 - year` for all entries of the last and current year. To prevent subtraction, use parentheses: `(month)-10` refers to the 10th of this month, whereas `month-10` would be 10 months ago. +**Week number** Week number of the year (Monday as the first day of the week) as +a decimal number. All days in a new year preceding the first Monday are +considered to be in week 0. + ### Account Filter entries by account, matching any entry this account is part of. The diff --git a/src/fava/util/date.py b/src/fava/util/date.py index 6f8ef7140..45e9de985 100644 --- a/src/fava/util/date.py +++ b/src/fava/util/date.py @@ -389,7 +389,11 @@ def parse_date( # noqa: PLR0911 match = WEEK_RE.match(string) if match: year, week = map(int, match.group(1, 2)) - start = datetime.date.fromisocalendar(year, week + 1, 1) + start = ( + datetime.datetime.strptime(f"{year}-W{week}-1", "%Y-W%W-%w") + .replace(tzinfo=datetime.timezone.utc) + .date() + ) return start, get_next_interval(start, Interval.WEEK) match = QUARTER_RE.match(string) diff --git a/tests/test_util_date.py b/tests/test_util_date.py index 23aeb2d44..ddb7caaba 100644 --- a/tests/test_util_date.py +++ b/tests/test_util_date.py @@ -220,6 +220,7 @@ def test_fiscal_substitute( ("2010-10-01", "2010-11-01", "2010-10"), ("2000-01-03", "2000-01-04", "2000-01-03"), ("2015-01-05", "2015-01-12", "2015-W01"), + ("2025-01-06", "2025-01-13", "2025-W01"), ("2015-04-01", "2015-07-01", "2015-Q2"), ("2014-01-01", "2016-01-01", "2014 to 2015"), ("2014-01-01", "2016-01-01", "2014-2015"),