@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.
24 lines • 1.44 kB
TypeScript
import { Temporal } from "../../internal/temporal.js";
import { TimeDurationUnit } from "../../types/time-duration-unit.js";
import "../../types/index.js";
/**
* Return the largest TimeDurationUnit from the provided array.
*
* - Returns the largest unit based on Temporal's unit order: hours > minutes > seconds > milliseconds > microseconds > nanoseconds.
* - Each unit may be singular or plural (`"day"` or `"days"`), as Temporal accepts; the result is
* the plural name.
* - Returns "" when `units` is not an array, is empty, or holds anything that is not a unit of
* this family.
* - **Compatibility:** before 1.16.0 an empty or invalid `units` returned a default unit
* (`"seconds"`).
*
* @param units array of TimeDurationUnits (singular or plural names) to evaluate
* @returns the largest TimeDurationUnit found in the array, or "" on invalid input
*
* @example getLargestTimeDurationUnit(["minutes", "seconds"]) // "minutes"
* @example getLargestTimeDurationUnit(["seconds", "milliseconds"]) // "seconds"
* @example getLargestTimeDurationUnit(["second", "minute"]) // "minutes" (singular names count as their plural)
* @example getLargestTimeDurationUnit([]) // "" (no unit to choose from)
* @example getLargestTimeDurationUnit(["seconds", "fortnights"]) // "" (an invalid unit)
*/
export declare function getLargestTimeDurationUnit(units: Array<TimeDurationUnit | Temporal.TimeUnit>): TimeDurationUnit | "";