go data_error ai_generated true

proto: google.protobuf.Timestamp: seconds value out of range

ID: go/protobuf-timestamp-out-of-range

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2025-04-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.x active — — —

Root Cause

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

中文

构造的 google.protobuf.Timestamp 的秒值超出有效范围 [-62135596800, 253402300799],通常来自零值 time.Time 或毫秒级的 Unix 时间戳。

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 90% fail

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

  2. 70% fail

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