Skip to content

fix(#370): allow modifiers after rounding in time_period_from/to - #374

Merged
MindFreeze merged 1 commit into
masterfrom
fix-370
May 26, 2026
Merged

fix(#370): allow modifiers after rounding in time_period_from/to#374
MindFreeze merged 1 commit into
masterfrom
fix-370

Conversation

@MindFreeze

Copy link
Copy Markdown
Owner

Fixes #370.

The calculateTimePeriod parser previously rejected Grafana-style anchors with a modifier after a rounding operator (e.g. now/d+7h, now-1d/d+23h), even though the README claims to follow Grafana's time range format. The parser now applies offset and rounding tokens left-to-right, unblocking windows like "yesterday 23:00 to today 07:00".

Summary

  • Refactored parseTimeString in src/utils.ts from a single-shot regex into an iterative tokenizer that walks offsets ([+-]N{unit}) and roundings (/{unit}) left-to-right. No new dependencies.
  • Added __tests__/calculateTimePeriod.test.ts (none existed) with deterministic time via jest.setSystemTime, covering the existing patterns, the new ones (now/d+7h, now-1d/d+23h, now/d-1h), the quiet-hours combo, and invalid-input rejection.
  • Documented the new examples and a "Quiet hours (23:00–07:00)" YAML snippet in the Time Period section of the README.

Examples now supported

Input Meaning
now/d+7h Today at 07:00
now-1d/d+23h Yesterday at 23:00
now/d-1h Yesterday at 23:00 (equivalent)

Test plan

  • npm run lint — no new warnings/errors
  • npm test — 114/114 tests pass across 9 suites, including the new calculateTimePeriod suite
  • Manual: configure a card with time_period_from: "now-1d/d+23h" and time_period_to: "now/d+7h" and confirm the 8-hour window renders correctly
  • Manual: re-test existing patterns (now-7d, now-1d/dnow/d) to confirm no regression

@MindFreeze
MindFreeze marked this pull request as ready for review May 26, 2026 06:03
@MindFreeze
MindFreeze merged commit f4349a8 into master May 26, 2026
1 check passed
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.

Allow for times relative to last midnight

1 participant