fix(#370): allow modifiers after rounding in time_period_from/to - #374
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #370.
The
calculateTimePeriodparser 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
parseTimeStringinsrc/utils.tsfrom a single-shot regex into an iterative tokenizer that walks offsets ([+-]N{unit}) and roundings (/{unit}) left-to-right. No new dependencies.__tests__/calculateTimePeriod.test.ts(none existed) with deterministic time viajest.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.Examples now supported
now/d+7hnow-1d/d+23hnow/d-1hTest plan
npm run lint— no new warnings/errorsnpm test— 114/114 tests pass across 9 suites, including the newcalculateTimePeriodsuitetime_period_from: "now-1d/d+23h"andtime_period_to: "now/d+7h"and confirm the 8-hour window renders correctlynow-7d,now-1d/d→now/d) to confirm no regression