go
data_error
ai_generated
true
proto: google.protobuf.Timestamp: 秒值超出范围
proto: google.protobuf.Timestamp: seconds value out of range
ID: go/protobuf-timestamp-out-of-range
80%修复率
86%置信度
0证据数
2025-04-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.x | active | — | — | — |
根因分析
构造的 google.protobuf.Timestamp 的秒值超出有效范围 [-62135596800, 253402300799],通常来自零值 time.Time 或毫秒级的 Unix 时间戳。
English
A google.protobuf.Timestamp was constructed with seconds outside the valid range [-62135596800, 253402300799], typically from a zero time.Time or a Unix timestamp in milliseconds.
解决方案
-
93% 成功率
Use timestamppb.New(t) which converts time.Time correctly, and validate t.IsZero() before conversion; for unset use a nil *timestamppb.Timestamp instead of zero.
-
90% 成功率
Convert from milliseconds explicitly: ts := timestamppb.New(time.UnixMilli(ms)) so the seconds/nanos split is correct.
无效尝试
常见但无效的做法:
-
90% 失败
Seconds must be in seconds; milliseconds overflow the valid range and produce an out-of-range error.
-
70% 失败
time.Time{}.Unix() is a large negative number that may fall outside the valid proto range depending on the year.