db/instances: expect non-Z time format (#196)
* db/instances: expect non-Z time format
* fixup! db/instances: expect non-Z time format
diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go
index 21900d7..6d60e86 100644
--- a/openstack/db/v1/instances/results.go
+++ b/openstack/db/v1/instances/results.go
@@ -1,6 +1,7 @@
package instances
import (
+ "encoding/json"
"time"
"github.com/gophercloud/gophercloud"
@@ -21,10 +22,10 @@
// Instance represents a remote MySQL instance.
type Instance struct {
// Indicates the datetime that the instance was created
- Created time.Time `json:"created"`
+ Created time.Time `json:"-"`
// Indicates the most recent datetime that the instance was updated.
- Updated time.Time `json:"updated"`
+ Updated time.Time `json:"-"`
// Indicates the hardware flavor the instance uses.
Flavor flavors.Flavor
@@ -56,6 +57,25 @@
Datastore datastores.DatastorePartial
}
+func (r *Instance) UnmarshalJSON(b []byte) error {
+ type tmp Instance
+ var s struct {
+ tmp
+ Created gophercloud.JSONRFC3339NoZ `json:"created"`
+ Updated gophercloud.JSONRFC3339NoZ `json:"updated"`
+ }
+ err := json.Unmarshal(b, &s)
+ if err != nil {
+ return err
+ }
+ *r = Instance(s.tmp)
+
+ r.Created = time.Time(s.Created)
+ r.Updated = time.Time(s.Updated)
+
+ return nil
+}
+
type commonResult struct {
gophercloud.Result
}
diff --git a/openstack/db/v1/instances/testing/fixtures.go b/openstack/db/v1/instances/testing/fixtures.go
index e0a0d28..8603e98 100644
--- a/openstack/db/v1/instances/testing/fixtures.go
+++ b/openstack/db/v1/instances/testing/fixtures.go
@@ -13,8 +13,8 @@
)
var (
- timestamp = "2015-11-12T14:22:42Z"
- timeVal, _ = time.Parse(time.RFC3339, timestamp)
+ timestamp = "2015-11-12T14:22:42"
+ timeVal, _ = time.Parse(gophercloud.RFC3339NoZ, timestamp)
)
var instance = `