Skip to content

Granularity

Module Export

Granularity: 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'

A type matching the calendar period sizes the module understands.

Remarks

The period size for startOf, endOf and periods.

Two of these are not fixed durations, which is the whole reason the module exists:

  • week begins on Monday, per ISO 8601.
  • month, quarter and year vary in length, and day does too in any zone observing daylight saving — a day is 23 or 25 hours long at a transition.

Being a literal union, a misspelling is caught at compile time rather than producing an empty or nonsensical result.

Examples

import 'calendar'
param granularity: Granularity = 'week'
from now startOf (granularity, 'Europe/Stockholm')

An unrecognised size fails to compile:

import 'calendar'
// Error: 'fortnight' is not a valid Granularity
from now startOf ('fortnight', 'UTC')