fix: TIME_GRAIN lookups for second/millisecond/unspecified grains #8646
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.
Problem
When viewing an infinite time range (
inf) without a validsmallest_time_grain, the derivedactiveTimeGraincan be set toTIME_GRAIN_SECOND. SinceTIME_GRAIN_SECOND,TIME_GRAIN_MILLISECOND, andTIME_GRAIN_UNSPECIFIEDwere missing from theTIME_GRAINrecord, this caused runtime failures in UI code that performed lookups (e.g., formatting, pivot chip labels).Solution
Core fix: Add missing grain entries to
TIME_GRAINrecord.Additional cleanup:
FromURLParamTimeGrainMap/ToURLParamTimeGrainMapMapwith existingDateTimeUnitToV1TimeGrain/V1TimeGrainToDateTimeUnitfromnew-grains.tseffectiveGrain(respectsminTimeGrain) instead of rawactiveTimeGrainin time series chartsgetAdjustedFetchTimeto use Luxon directly instead of legacy helper functionsformatDateTimeByGrainutility for grain-aware datetime formattingChanges
Core fix
Add
MILLISECOND,SECOND,UNSPECIFIEDtoTIME_GRAINrecord andPeriodenumMapper consolidation
Remove duplicate mappers, use
V1TimeGrainToDateTimeUnitthroughoutTime series
Use
effectiveGrainwithisGrainAllowedguardUtilities
Add
formatDateTimeByGrain, simplifygetAdjustedFetchTimeTests
Add 12 tests for
formatDateTimeByGrainTechnical debt
This is a targeted fix. The underlying issue is type fragmentation across
TIME_GRAIN,V1TimeGrain,AvailableTimeGrain,Period, andTimeUnit—all of which duplicate Luxon'sDateTimeUnit. A TODO comment documents the path forward: consolidate around Luxon utilities per the pattern innew-grains.ts.Checklist: