Skip to content

sortDates

sortDates(dates: string[], order?: "asc" | "desc"): string[]

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.
ParameterTypeDescription
datesstring[]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

import { sortDates } from "@northguild/gmt/plain/calculate";
sortDates(["2024-03-10", "2024-01-01", "2024-02-15"]) // ["2024-01-01", "2024-02-15", "2024-03-10"]
dates
output 

plain/calculate/sortDates.ts