Enable parsing times in strings which have been set using JSON

If the data of a record was set using CONTENT, MERGE, or DIFF, then any Javascript Date values were treated as strings. These values are now parsed if the field is defined as a datetime field.
This commit is contained in:
Tobie Morgan Hitchcock 2017-12-12 01:05:40 +00:00
parent cacdf6dd49
commit 3eef62067a

View file

@ -220,9 +220,12 @@ func ConvertToBoolean(obj interface{}) (val bool, err error) {
}
func ConvertToDatetime(obj interface{}) (val time.Time, err error) {
if now, ok := obj.(time.Time); ok {
switch now := obj.(type) {
case time.Time:
val = now
} else {
case string:
val, err = time.Parse(time.RFC3339Nano, now)
default:
err = fmt.Errorf("Expected a datetime, but found '%v'", obj)
}
return
@ -255,7 +258,12 @@ func ConvertToRecord(obj interface{}, tb string) (val *sql.Thing, err error) {
err = fmt.Errorf("Expected a record of type '%s', but found '%v'", tb, obj)
}
} else {
err = fmt.Errorf("Expected a record of type '%s', but found '%v'", tb, obj)
switch tb {
default:
err = fmt.Errorf("Expected a record of type '%s', but found '%v'", tb, obj)
case "":
err = fmt.Errorf("Expected a record of any type, but found '%v'", tb, obj)
}
}
return
}