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

Update date.py #1807

Merged
merged 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/fava/help/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/fava/util/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, 1)
yagebu marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_util_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down