@cutticat/duration-constants
Tired of defining the same duration constants again in every project? So are we.
The package is only those numbers. It has no dependencies. A bundler keeps the constants an import actually uses, so a project that pulls the package in barely notices the weight.
Counts a duration in nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days, and weeks.
A second, a minute, an hour, a day, and a week are fixed lengths. Months use Gregorian day counts: February is 28 days, leap February is 29, four months are 30, and the rest are 31. A common year is 365 days of 24 hours. A leap year is 366. These values are not calendar dates and do not follow a time zone.
The field for a fixed unit is 1. Larger units are fractions. A 31-day month does not divide into whole weeks. year.nanoseconds sits above Number.MAX_SAFE_INTEGER. That stored value is exact, and nearby integers are not all representable.
Install
pnpm add @cutticat/duration-constants
Usage
import { day, leapYear, months, second, shortestMonth } from "@cutticat/duration-constants"
second.milliseconds // 1_000
day.hours // 24
months.february.weeks // 4
months.leapFebruary.days // 29
shortestMonth.days // 28
leapYear.days // 366
API
nanosecond,microsecond,millisecond,second,minute,hour,day,week— one of that unit, counted in every fieldmonths—januarythroughdecember, plusleapFebruaryshortestMonth— February in a common year, 28 dayslongestMonth— December, 31 daysyear— a common year, 365 days of 24 hoursleapYear— a leap year, 366 days of 24 hourstimeValuesFromMilliseconds— split a millisecond count into the same fields
Documentation
Requirements
- Node.js >= 22.18.0
- pnpm >= 10.17.0
- TypeScript >= 5.9.0