Skip to content

getLargestDateDurationUnit

getLargestDateDurationUnit(units: ("years" | "months" | "weeks" | "days" | DateUnit)[]): "years" | "months" | "weeks" | "days" | ""

Return the largest DateDurationUnit from the provided array.

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

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

import { getLargestDateDurationUnit } from "@northguild/gmt/plain/calculate";
getLargestDateDurationUnit(["months", "days"]) // "months"
units
output 

plain/calculate/getLargestDateDurationUnit.ts