sortZoned
Signature
Section titled “Signature”sortZoned(zonedDateTimes: string[], order?: "asc" | "desc"): string[]import { sortZoned } from "@northguild/gmt/zoned/calculate";Sort an array of ZonedDateTime values in ascending or descending order.
- Invalid dates are filtered out.
- Defaults to ascending order (earliest first).
- Returns empty array if no valid dates.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
zonedDateTimes |
string[] |
Array of ISO ZonedDateTime strings |
order |
"asc" | "desc" |
“asc” for ascending (earliest first) | “desc” for descending (latest first) |
Returns
Section titled “Returns”Sorted array of zoned datetime strings
Examples
Section titled “Examples”sortZoned(["2024-03-10T12:00:00[America/New_York]", "2024-01-01T08:00:00[America/New_York]", "2024-02-15T15:30:00[America/New_York]"]) // ["2024-01-01T08:00:00-05:00[America/New_York]", "2024-02-15T15:30:00-05:00[America/New_York]", "2024-03-10T12:00:00-04:00[America/New_York]"]sortZoned(["2024-03-10T12:00:00[America/New_York]", "2024-01-01T08:00:00[America/New_York]", "2024-02-15T15:30:00[America/New_York]"], "desc") // ["2024-03-10T12:00:00-04:00[America/New_York]", "2024-02-15T15:30:00-05:00[America/New_York]", "2024-01-01T08:00:00-05:00[America/New_York]"]sortZoned(["invalid", "2024-01-01T08:00:00[America/New_York]", "2024-02-15T15:30:00[America/New_York]"]) // ["2024-01-01T08:00:00-05:00[America/New_York]", "2024-02-15T15:30:00-05:00[America/New_York]"]sortZoned([]) // []