Skip to content

sortDateTimes

sortDateTimes(dateTimes: string[], order?: "asc" | "desc"): string[]
import { sortDateTimes } from "@northguild/gmt/plain/calculate";

Sort an array of PlainDateTime values in ascending or descending order.

  • Returns empty array if no valid datetimes.
  • Validation is performed on each item in the array.
Parameter Type Description
dateTimes string[] Array of ISO PlainDateTime strings (e.g. “2024-03-10T12:00:00”)
order "asc" | "desc" “asc” for ascending (earliest first) | “desc” for descending (latest first)

Sorted array of datetime strings

sortDateTimes(["2024-03-10T12:00:00", "2024-01-01T08:00:00", "2024-02-15T15:30:00"]) // ["2024-01-01T08:00:00", "2024-02-15T15:30:00", "2024-03-10T12:00:00"]
sortDateTimes([]) // []

plain/calculate/sortDateTimes.ts