3 ms·
Can someone explain why, if the start date was 1970, why is it rolling over to december 1901? Why wouldn't it roll over to the start date in 1970 again?
by snapplebobapple 4y ago
Can someone explain why, if the start date was 1970, why is it rolling over to december 1901? Why wouldn't it roll over to the start date in 1970 again?
- sour-taste 4y agoAssuming I understand your question correctly: If the counter is stored as a signed int32 then the rollover will be to the smallest representable signed 32 which corresponds to the 1901 date. It's stored signed because software (particularly old software) wanted to be able to manipulate pre 1970 dates.
- budoso 4y agoI’d guess that it’s because it’s a signed int? So the value can be negative. Probably depends on the library implementation though.
- gs17 4y agoIt's a signed integer. The overflow will make the number negative, not zero.
- SAI_Peregrinus 4y agoAnd because it's JS. Not every language defines signed integer overflow as wrapping.
- chipsa 4y agoMost languages assume twos complement signed numbers. So an uncaught overflow will be wrapped around JS specifically won’t necessarily wrap at this point, because adding one to the Max 32 but signed int maybe be a float.