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

其他格式: JSON · Markdown 中文 · English
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.

generic

解决方案

  1. 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.
  2. 90% 成功率
    Convert from milliseconds explicitly: ts := timestamppb.New(time.UnixMilli(ms)) so the seconds/nanos split is correct.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Seconds must be in seconds; milliseconds overflow the valid range and produce an out-of-range error.

  2. 70% 失败

    time.Time{}.Unix() is a large negative number that may fall outside the valid proto range depending on the year.