fix(api): support generic Nd period presets (90d, 365d, …)
Some checks failed
Tests / test (push) Has been cancelled
Static Analysis / static (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
Static Analysis / static (push) Has been cancelled

_preset_to_range only special-cased today/30d/custom and fell through to 7d for
everything else, so the Fuel Log tab's default "90d" silently returned 7 days.
Parse any positive `Nd` preset into a today-(N-1)..today window. Backward-
compatible: today/30d/custom and the 7d default are unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kianiadee 2026-06-12 00:19:06 +03:00
parent c42a500d4b
commit 024b698bca

View file

@ -356,6 +356,9 @@ def _preset_to_range(period: str | None, start_date, end_date):
except ValueError:
return default
return _d(start_date, today), _d(end_date, today)
# generic 'Nd' window (e.g. 7d / 30d / 90d / 365d) — used by the Fuel Log tab
if p.endswith("d") and p[:-1].isdigit() and int(p[:-1]) > 0:
return today - timedelta(days=int(p[:-1]) - 1), today
# default + '7d'
return today - timedelta(days=6), today