From fea610f7b4427b163f262486bd300e8f6da03bd6 Mon Sep 17 00:00:00 2001 From: theo-delaune-argus Date: Thu, 12 Mar 2020 16:33:50 +0100 Subject: [PATCH] Store time in RFC3339Nano to keep nanoseconds --- command.go | 2 +- command_test.go | 4 ++-- internal/proto/write_buffer_test.go | 5 +++-- internal/proto/writer.go | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/command.go b/command.go index 266e389..fa1b03e 100644 --- a/command.go +++ b/command.go @@ -671,7 +671,7 @@ func (cmd *StringCmd) Time() (time.Time, error) { if cmd.err != nil { return time.Time{}, cmd.err } - return time.Parse(time.RFC3339, cmd.Val()) + return time.Parse(time.RFC3339Nano, cmd.Val()) } func (cmd *StringCmd) Scan(val interface{}) error { diff --git a/command_test.go b/command_test.go index e9fc958..c7ecbca 100644 --- a/command_test.go +++ b/command_test.go @@ -72,14 +72,14 @@ var _ = Describe("Cmd", func() { }) It("supports time.Time", func() { - tm := time.Date(2019, 01, 01, 0, 0, 0, 0, time.UTC) + tm := time.Date(2019, 01, 01, 9, 45, 10, 222125, time.UTC) err := client.Set("time_key", tm, 0).Err() Expect(err).NotTo(HaveOccurred()) s, err := client.Get("time_key").Result() Expect(err).NotTo(HaveOccurred()) - Expect(s).To(Equal("2019-01-01T00:00:00Z")) + Expect(s).To(Equal("2019-01-01T09:45:10.000222125Z")) tm2, err := client.Get("time_key").Time() Expect(err).NotTo(HaveOccurred()) diff --git a/internal/proto/write_buffer_test.go b/internal/proto/write_buffer_test.go index 4a9339e..2953446 100644 --- a/internal/proto/write_buffer_test.go +++ b/internal/proto/write_buffer_test.go @@ -55,13 +55,14 @@ var _ = Describe("WriteBuffer", func() { }) It("should append time", func() { - err := wr.WriteArgs([]interface{}{time.Unix(1414141414, 0).UTC()}) + tm := time.Date(2019, 01, 01, 9, 45, 10, 222125, time.UTC) + err := wr.WriteArgs([]interface{}{tm}) Expect(err).NotTo(HaveOccurred()) err = wr.Flush() Expect(err).NotTo(HaveOccurred()) - Expect(buf.Len()).To(Equal(31)) + Expect(buf.Len()).To(Equal(41)) }) It("should append marshalable args", func() { diff --git a/internal/proto/writer.go b/internal/proto/writer.go index cd83d65..d552f1e 100644 --- a/internal/proto/writer.go +++ b/internal/proto/writer.go @@ -93,7 +93,7 @@ func (w *Writer) writeArg(v interface{}) error { } return w.int(0) case time.Time: - return w.string(v.Format(time.RFC3339)) + return w.string(v.Format(time.RFC3339Nano)) case encoding.BinaryMarshaler: b, err := v.MarshalBinary() if err != nil {