Skip to content

isValidZoneBucketUnit

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 and floorToZone/bucketRange accept both.
  • Accepts any input type and returns false for non-string values.
  • Uses type assertion to narrow the type.
  • Narrower than isValidDateTimeUnit on 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 are getQuarter’s and getFiscalPeriod’s.
  • floorToZone returns "" and bucketRange returns [] 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.
ParameterTypeDescription
unitunknowncandidate value of any type

boolean indicating validity

import { isValidZoneBucketUnit } from "@northguild/gmt/calendar/validate";
isValidZoneBucketUnit("hour") // true
output 

calendar/validate/isValidZoneBucketUnit.ts