Timestamps and scheduling guides
Timestamp sorting: precision, negative values and range
Normalize units before ordering events, preserve subsecond precision and validate date ranges.
Normalize units first
Comparing raw seconds with milliseconds orders counts rather than instants. A smaller count can represent a later time when the unit differs.
Convert all records to the agreed unit before numeric sorting. Keep the source unit when ingestion contracts differ.
Keep negative values meaningful
A negative Unix timestamp describes an instant before the epoch. It is not automatically an error or an unsigned identifier.
The example is one second before 1970 in UTC. Select the unit explicitly for ambiguous historical values instead of applying a modern digit heuristic.
-1 second → 1969-12-31T23:59:59.000ZPreserve useful precision
Events sharing an integer second can still differ in milliseconds or microseconds. Rounding too early destroys ordering evidence.
JavaScript Date provides millisecond resolution; another source can be finer. Keep the original high-resolution value or an agreed secondary ordering key.
Validate ranges and tie-breakers
A library’s supported date range is finite. Numeric-looking input can overflow or be outside that range even when it parses as a number.
Test minimum and maximum supported dates and equal timestamps. Distributed event order may require sequence numbers; a wall clock alone is not a total causal order.