Skip to content

getLargestDateTimeDurationUnit

getLargestDateTimeDurationUnit(units: (keyof DurationLike | DateTimeUnit)[]): keyof DurationLike | ""

Return the largest DateTimeDurationUnit from the provided array.

  • Returns the largest unit based on Temporal’s unit order: years > months > weeks > days > 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").
ParameterTypeDescription
units(keyof DurationLike | DateTimeUnit)[]array of DateTimeDurationUnits (singular or plural names) to evaluate

the largest DateTimeDurationUnit found in the array, or "" on invalid input

import { getLargestDateTimeDurationUnit } from "@northguild/gmt/plain/calculate";
getLargestDateTimeDurationUnit(["hours", "minutes", "seconds"]) // "hours"
units
output 

plain/calculate/getLargestDateTimeDurationUnit.ts