Event Timestamps Need Units, Not Guesswork
An event can have a valid name, a stable identifier, and a timestamp that lands decades outside the reporting period. The request may still be valid JSON. A successful HTTP response would not tell you whether the timestamp meant seconds or milliseconds. Event timestamp validation should start with a declared unit, not a guess based on the number of digits. This tutorial builds a small, offline…
The article emphasizes the importance of specifying timestamp units in event data to avoid confusion and errors in interpretation. It highlights that event timestamps can be valid JSON but may still be ambiguous regarding whether they represent seconds or milliseconds. The author suggests that a contract should be established for timestamp units, such as using a field with a defined unit like `occurred_at_ms` or a versioned source contract that explicitly declares the unit.
By converting the timestamp to a single unit at the boundary and validating the normalized value, the system can ensure accurate interpretation. The article provides a Node.js example demonstrating how to implement this validation process, emphasizing the need for explicit conversion checks and rejecting non-numeric or fractional values.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.