Skip to content

sortDates

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

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

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

Sorted array of date strings

sortDates(["2024-03-10", "2024-01-01", "2024-02-15"]) // ["2024-01-01", "2024-02-15", "2024-03-10"]
sortDates([]) // []

plain/calculate/sortDates.ts