Skip to content

Commit

Permalink
Store time in RFC3339Nano to keep nanoseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-delaune-argus committed Mar 13, 2020
1 parent 1c4dd84 commit fea610f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions internal/proto/write_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion internal/proto/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fea610f

Please sign in to comment.