better implementation for unmashaling times
diff --git a/results.go b/results.go
index e11a492..0de2223 100644
--- a/results.go
+++ b/results.go
@@ -151,12 +151,13 @@
type JSONRFC3339MilliNoZ time.Time
func (jt *JSONRFC3339MilliNoZ) UnmarshalJSON(data []byte) error {
- b := bytes.NewBuffer(data)
- dec := json.NewDecoder(b)
var s string
- if err := dec.Decode(&s); err != nil {
+ if err := json.Unmarshal(data, &s); err != nil {
return err
}
+ if s == "" {
+ return nil
+ }
t, err := time.Parse(RFC3339MilliNoZ, s)
if err != nil {
return err
@@ -168,12 +169,13 @@
type JSONRFC1123 time.Time
func (jt *JSONRFC1123) UnmarshalJSON(data []byte) error {
- b := bytes.NewBuffer(data)
- dec := json.NewDecoder(b)
var s string
- if err := dec.Decode(&s); err != nil {
+ if err := json.Unmarshal(data, &s); err != nil {
return err
}
+ if s == "" {
+ return nil
+ }
t, err := time.Parse(time.RFC1123, s)
if err != nil {
return err
@@ -185,13 +187,13 @@
type JSONUnix time.Time
func (jt *JSONUnix) UnmarshalJSON(data []byte) error {
- b := bytes.NewBuffer(data)
- dec := json.NewDecoder(b)
var s string
- if err := dec.Decode(&s); err != nil {
+ if err := json.Unmarshal(data, &s); err != nil {
return err
}
-
+ if s == "" {
+ return nil
+ }
unix, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
@@ -207,10 +209,8 @@
type JSONRFC3339NoZ time.Time
func (jt *JSONRFC3339NoZ) UnmarshalJSON(data []byte) error {
- b := bytes.NewBuffer(data)
- dec := json.NewDecoder(b)
var s string
- if err := dec.Decode(&s); err != nil {
+ if err := json.Unmarshal(data, &s); err != nil {
return err
}
if s == "" {