Skip to content

Commit

Permalink
feat: add support for time.Duration write and scan
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrodash committed Oct 21, 2021
1 parent 0260525 commit 2f1b74e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/proto/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ func Scan(b []byte, v interface{}) error {
var err error
*v, err = time.Parse(time.RFC3339Nano, util.BytesToString(b))
return err
case *time.Duration:
n, err := util.ParseInt(b, 10, 64)
if err != nil {
return err
}
*v = time.Duration(n)
return nil
case encoding.BinaryUnmarshaler:
return v.UnmarshalBinary(b)
default:
Expand Down
2 changes: 2 additions & 0 deletions internal/proto/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func (w *Writer) WriteArg(v interface{}) error {
case time.Time:
w.numBuf = v.AppendFormat(w.numBuf[:0], time.RFC3339Nano)
return w.bytes(w.numBuf)
case time.Duration:
return w.int(v.Nanoseconds())
case encoding.BinaryMarshaler:
b, err := v.MarshalBinary()
if err != nil {
Expand Down

0 comments on commit 2f1b74e

Please sign in to comment.