Support time location on form binding (#1117)

This commit is contained in:
delphinus
2017-09-28 23:23:18 +09:00
committed by Bo-Yi Wu
parent 5afc5b1973
commit a8c53949e5
2 changed files with 21 additions and 8 deletions

View File

@ -163,6 +163,14 @@ func setTimeField(val string, structField reflect.StructField, value reflect.Val
l = time.UTC
}
if locTag := structField.Tag.Get("time_location"); locTag != "" {
loc, err := time.LoadLocation(locTag)
if err != nil {
return err
}
l = loc
}
t, err := time.ParseInLocation(timeFormat, val, l)
if err != nil {
return err