Commit 720c323e authored by astaxie's avatar astaxie Committed by GitHub

Merge pull request #2652 from gouyang/gouyang/dev

Support timeformat "2006-01-02T15:04:05"
parents 248beab5 47e351e1
...@@ -30,6 +30,7 @@ const ( ...@@ -30,6 +30,7 @@ const (
formatTime = "15:04:05" formatTime = "15:04:05"
formatDate = "2006-01-02" formatDate = "2006-01-02"
formatDateTime = "2006-01-02 15:04:05" formatDateTime = "2006-01-02 15:04:05"
formatDateTimeT = "2006-01-02T15:04:05"
) )
// Substr returns the substr from start to length. // Substr returns the substr from start to length.
...@@ -360,8 +361,13 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e ...@@ -360,8 +361,13 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e
value = value[:25] value = value[:25]
t, err = time.ParseInLocation(time.RFC3339, value, time.Local) t, err = time.ParseInLocation(time.RFC3339, value, time.Local)
} else if len(value) >= 19 { } else if len(value) >= 19 {
if strings.Contains(value, "T") {
value = value[:19]
t, err = time.ParseInLocation(formatDateTimeT, value, time.Local)
} else {
value = value[:19] value = value[:19]
t, err = time.ParseInLocation(formatDateTime, value, time.Local) t, err = time.ParseInLocation(formatDateTime, value, time.Local)
}
} else if len(value) >= 10 { } else if len(value) >= 10 {
if len(value) > 10 { if len(value) > 10 {
value = value[:10] value = value[:10]
...@@ -373,7 +379,6 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e ...@@ -373,7 +379,6 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e
} }
t, err = time.ParseInLocation(formatTime, value, time.Local) t, err = time.ParseInLocation(formatTime, value, time.Local)
} }
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment