tstime/mono: make json.Unmarshal of a zero time.Time yield a zero Time

This was the proximate cause of #2579.
#2582 is a deeper fix, but this will remain
as a footgun, so may as well fix it too.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2021-08-04 10:36:51 -07:00
committed by Josh Bleecher Snyder
parent f3c96df162
commit f013960d87
2 changed files with 21 additions and 0 deletions

View File

@@ -121,6 +121,10 @@ func (t *Time) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
if tt.IsZero() {
*t = 0
return nil
}
*t = Now().Add(-time.Since(tt))
return nil
}