From 5b8a483a9623998625fe970e78307b0c5e064d51 Mon Sep 17 00:00:00 2001 From: deads2k Date: Fri, 23 Jun 2017 13:51:22 -0400 Subject: [PATCH] make proto time precision match json --- .../apimachinery/pkg/apis/meta/v1/time_proto.go | 11 +++++++++-- .../k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_proto.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_proto.go index 5520529dd3c..ed72186b49f 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_proto.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_proto.go @@ -42,7 +42,10 @@ func (m *Time) ProtoTime() *Timestamp { } return &Timestamp{ Seconds: m.Time.Unix(), - Nanos: int32(m.Time.Nanosecond()), + // leaving this here for the record. our JSON only handled seconds, so this results in writes by + // protobuf clients storing values that aren't read by json clients, which results in unexpected + // field mutation, which fails various validation and equality code. + // Nanos: int32(m.Time.Nanosecond()), } } @@ -64,7 +67,11 @@ func (m *Time) Unmarshal(data []byte) error { if err := p.Unmarshal(data); err != nil { return err } - m.Time = time.Unix(p.Seconds, int64(p.Nanos)).Local() + // leaving this here for the record. our JSON only handled seconds, so this results in writes by + // protobuf clients storing values that aren't read by json clients, which results in unexpected + // field mutation, which fails various validation and equality code. + // m.Time = time.Unix(p.Seconds, int64(p.Nanos)).Local() + m.Time = time.Unix(p.Seconds, int64(0)).Local() return nil } diff --git a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go index 3ab1d5fd1ae..c0fafab9bfc 100644 --- a/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time_test.go @@ -152,7 +152,7 @@ func TestTimeProto(t *testing.T) { input Time }{ {Time{}}, - {Date(1998, time.May, 5, 1, 5, 5, 50, time.Local)}, + {Date(1998, time.May, 5, 1, 5, 5, 0, time.Local)}, {Date(1998, time.May, 5, 5, 5, 5, 0, time.Local)}, }