Repository navigation
fix(os/gtime): fix Timestamp overflow outside the UnixNano range - #4989
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4989 +/- ##
==========================================
- Coverage 85.11% 85.10% -0.02%
==========================================
Files 893 893
Lines 47141 47141
==========================================
- Hits 40125 40120 -5
- Misses 7016 7021 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
6364afe to
c6d46ab
Compare
|
Thanks for updating the branch. The new
I have not added the |
Timestamp,TimestampMilliandTimestampMicrodivideUnixNano().UnixNanois only defined for the years 1678 to 2262, so outside that range the result is wrong:1600-01-01 UTCgives6770648073instead of-11676096000. Dates like9999-12-31are common as "no end date" values.TimestampStr,TimestampMilliStrandTimestampMicroStrreturn the same wrong numbers.The fix uses
Unix(),UnixMilli()andUnixMicro()of the standard library, which do not overflow there.One behaviour difference: for a time before 1970 with a fractional second the result is now floored, as
time.Time.Unixdoes (1969-12-31 23:59:59.5gives-1, it was0).Test:
Test_Timestamp_OutOfUnixNanoRangefails on master withEXPECT -4852116232 == 253402300799. I rango test -race ./os/gtime/withTZ=Asia/Shanghai.🤖 Generated with Claude Code