sortUtc
Signature
Section titled “Signature”sortUtc(utcDateTimes: string[], order?: "asc" | "desc"): string[]import { sortUtc } from "@northguild/gmt/utc/calculate";Sort an array of UTC datetime values in ascending or descending order.
- Filters invalid values before sorting.
- Supports “asc” (earliest first) or “desc” (latest first).
- Returns [] if array is empty or has no valid values.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
utcDateTimes |
string[] |
Array of ISO datetime strings (e.g. “2024-03-10T12:00:00Z”) |
order |
"asc" | "desc" |
“asc” for ascending (earliest first) | “desc” for descending (latest first) |
Returns
Section titled “Returns”Sorted array of UTC datetime strings
Examples
Section titled “Examples”sortUtc(["2024-03-12T12:00:00Z", "2024-03-10T12:00:00Z", "2024-03-15T12:00:00Z"]) // ["2024-03-10T12:00:00Z", "2024-03-12T12:00:00Z", "2024-03-15T12:00:00Z"]sortUtc(["2024-03-12T12:00:00Z", "2024-03-10T12:00:00Z", "2024-03-15T12:00:00Z"], "desc") // ["2024-03-15T12:00:00Z", "2024-03-12T12:00:00Z", "2024-03-10T12:00:00Z"]sortUtc(["invalid", "2024-03-10T12:00:00Z", "also invalid"]) // ["2024-03-10T12:00:00Z"]sortUtc([]) // []