From 38ce619d5565dabf5515a7528a5395b1f429a8d6 Mon Sep 17 00:00:00 2001 From: mailhot001 <151871234+mailhot001@users.noreply.github.com> Date: Thu, 16 May 2024 12:18:54 -0400 Subject: [PATCH 1/4] Update date.py remove the + 1 on the week RE match in date parser so that the week number match the front end displayed week number. --- src/fava/util/date.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fava/util/date.py b/src/fava/util/date.py index 4ab7797f2..8f3ca2b30 100644 --- a/src/fava/util/date.py +++ b/src/fava/util/date.py @@ -382,7 +382,7 @@ 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.date.fromisocalendar(year, week, 1) return start, get_next_interval(start, Interval.WEEK) match = QUARTER_RE.match(string) From 6d75bb35a4b2861e7a4abf909a3168781accf33d Mon Sep 17 00:00:00 2001 From: mailhot001 Date: Fri, 31 May 2024 11:56:50 -0400 Subject: [PATCH 2/4] convert week parsing to match d3.js --- src/fava/util/date.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fava/util/date.py b/src/fava/util/date.py index 8f3ca2b30..0dec475b1 100644 --- a/src/fava/util/date.py +++ b/src/fava/util/date.py @@ -382,7 +382,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) + 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) From 50e320206928baf781e086f23255a324bcaa9c80 Mon Sep 17 00:00:00 2001 From: mailhot001 Date: Wed, 5 Jun 2024 10:17:15 -0400 Subject: [PATCH 3/4] file made prettier --- src/fava/help/filters.md | 4 ++++ tests/test_util_date.py | 2 ++ 2 files changed, 6 insertions(+) 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/tests/test_util_date.py b/tests/test_util_date.py index 23aeb2d44..c01d49978 100644 --- a/tests/test_util_date.py +++ b/tests/test_util_date.py @@ -220,6 +220,8 @@ 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"), + ("2017-01-02", "2017-01-09", "2017-W01"), + ("2028-01-03", "2028-01-10", "2028-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"), From 525e2ce3901c3dc0988662455b1076b6b7695ea4 Mon Sep 17 00:00:00 2001 From: mailhot001 Date: Wed, 5 Jun 2024 10:31:36 -0400 Subject: [PATCH 4/4] corrected the test to show difference between iso and %W week numbering --- tests/test_util_date.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_util_date.py b/tests/test_util_date.py index c01d49978..ddb7caaba 100644 --- a/tests/test_util_date.py +++ b/tests/test_util_date.py @@ -220,8 +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"), - ("2017-01-02", "2017-01-09", "2017-W01"), - ("2028-01-03", "2028-01-10", "2028-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"),