isValidZoneBucketUnit
Signature
Section titled “Signature”isValidZoneBucketUnit(unit: unknown): unit is SmallestUnit<ZoneBucketUnit>Return true when unit is a valid ZoneBucketUnit.
- Valid units are: “hour”, “day”, “week”, “month”, singular or plural (
"days"), as Temporal §13.17 names a unit either way andfloorToZone/bucketRangeaccept both. - Accepts any input type and returns false for non-string values.
- Uses type assertion to narrow the type.
- Narrower than
isValidDateTimeUniton purpose: these are the boundaries a calendar in a zone actually has. Sub-hour units need no zone, and “year” is left out because the calendar and fiscal year questions aregetQuarter’s andgetFiscalPeriod’s. floorToZonereturns "" andbucketRangereturns [] for a unit they do not recognise — the same sentinels they return for an unusable instant. Check the unit here to tell a misconfigured rollup apart from a bad timestamp.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
unit | unknown | candidate value of any type |
Returns
Section titled “Returns”boolean indicating validity
Related types
Section titled “Related types”Examples
Section titled “Examples”import { isValidZoneBucketUnit } from "@northguild/gmt/calendar/validate";
isValidZoneBucketUnit("hour") // true