Skip to content

sortUnix

sortUnix(unixValues: (string | number)[], order?: "asc" | "desc"): number[]

Sort an array of Unix timestamp values in ascending or descending order.

  • Drops values that are not unix epochs before sorting: anything that is not a safe integer or a string of optionally negative ASCII digits, and values outside the Temporal instant range (±8.64e15, which contains every seconds and milliseconds epoch).
  • Supports “asc” (earliest first) or “desc” (latest first).
  • Returns [] if array is empty or has no valid values.
ParameterTypeDescription
unixValues(string | number)[]Array of Unix epochs as numbers or digit strings (e.g. 1699531200 or “1699531200”); digit strings are returned as numbers
order"asc" | "desc"“asc” for ascending (earliest first) | “desc” for descending (latest first)

Sorted array of Unix timestamps

import { sortUnix } from "@northguild/gmt/unix/calculate";
sortUnix([1706659200000, 1704067200000, 1700000000000]) // [1700000000000, 1704067200000, 1706659200000]
unixValues
output 

unix/calculate/sortUnix.ts