sortDateTimes
Signature
Section titled “Signature”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.
Parameters
Section titled “Parameters”| 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) |
Returns
Section titled “Returns”Sorted array of datetime strings
Examples
Section titled “Examples”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([]) // []