You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DatetimeWithNanoseconds.timestamp_pb() returns incorrect seconds for fractional timestamps #18561
For the first two inputs, actual.ToJsonString() gives a time one second later. For the year-9999 input, it raises ValueError because the seconds exceed the protobuf timestamp range. The modern-date control is correct.
Expected behavior and likely cause
timestamp_pb() should match protobuf's Timestamp.FromJsonString() for the same RFC 3339 value.
The helper currently uses int(delta.total_seconds()). Before 1970, this truncates negative fractional seconds toward zero, while protobuf requires the preceding whole second plus non-negative nanoseconds. Near the upper date limit, the floating-point conversion rounds up to the next second.
Calculating seconds from delta.days * 86400 + delta.seconds should avoid both problems without changing how nanoseconds are stored. No credentials or network access are needed to reproduce this.
Activity