Why this matters

The bug. | 0 is a popular JS shorthand for 'cast to int' — but it casts to int32, not 'integer'. Date.now() / 1000 for any date past 2^31 (≈ 2038-01-19) becomes a value larger than Number.MAX_SAFE_INTEGER / 2, then | 0 wraps it modulo 2^32 and reinterprets as signed. Result: negative timestamps right around 2038. Lookup tables keyed on this value go haywire.

The fix. Use Math.floor (or Math.trunc) — neither has a 32-bit limit, and both return a regular JS number that's safe up to 2^53.

Heuristic. Anywhere you see | 0, >>> 0, or ~~x outside genuinely-bitmask code, ask: are we accidentally casting to int32?

Review heuristic

Any arithmetic on a number that came from input, including a length, a count, or a timestamp, should be reviewed for what happens at the type's max value. A 32-bit byte counter overflows after 4 GB.

External reference: CWE-190: Integer Overflow or Wraparound.

Y2038 problem; CWE-190.