@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
33 lines • 1.23 kB
TypeScript
import { Temporal } from "./temporal.js";
import { DateTimeUnit } from "../types/date-time-unit.js";
import "../types/index.js";
/**
* Singular DateTimeUnit to its `Temporal.Duration` field name.
*
* Example lookups:
* - DURATION_FIELD_BY_UNIT.day => "days"
* - DURATION_FIELD_BY_UNIT.nanosecond => "nanoseconds"
*/
export declare const DURATION_FIELD_BY_UNIT: {
readonly year: "years";
readonly month: "months";
readonly week: "weeks";
readonly day: "days";
readonly hour: "hours";
readonly minute: "minutes";
readonly second: "seconds";
readonly millisecond: "milliseconds";
readonly microsecond: "microseconds";
readonly nanosecond: "nanoseconds";
};
/**
* Extract the whole-unit span from a `Temporal.Duration` measured with `largestUnit: unit`.
*
* - Floors the field so a partial trailing amount never inflates a boundary count.
* - Does NOT validate the unit — caller ensures the duration was measured in it.
*
* @param duration Temporal.Duration produced by `until({ largestUnit: unit })`
* @param unit DateTimeUnit the duration was measured in
* @returns whole number of units spanned
*/
export declare function getUnitSpan(duration: Temporal.Duration, unit: DateTimeUnit): number;