From 47e351e11db86d120ccb3976d3c4388d07954139 Mon Sep 17 00:00:00 2001 From: Guohua Ouyang Date: Fri, 19 May 2017 09:22:27 +0800 Subject: [PATCH] Support timeformat "2006-01-02T15:04:05" Fixes #2649 Signed-off-by: Guohua Ouyang --- templatefunc.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index 2591c88e..a104fd24 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -27,9 +27,10 @@ import ( ) const ( - formatTime = "15:04:05" - formatDate = "2006-01-02" - formatDateTime = "2006-01-02 15:04:05" + formatTime = "15:04:05" + formatDate = "2006-01-02" + formatDateTime = "2006-01-02 15:04:05" + formatDateTimeT = "2006-01-02T15:04:05" ) // Substr returns the substr from start to length. @@ -360,8 +361,13 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e value = value[:25] t, err = time.ParseInLocation(time.RFC3339, value, time.Local) } else if len(value) >= 19 { - value = value[:19] - t, err = time.ParseInLocation(formatDateTime, value, time.Local) + if strings.Contains(value, "T") { + value = value[:19] + t, err = time.ParseInLocation(formatDateTimeT, value, time.Local) + } else { + value = value[:19] + t, err = time.ParseInLocation(formatDateTime, value, time.Local) + } } else if len(value) >= 10 { if len(value) > 10 { value = value[:10] @@ -373,7 +379,6 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e } t, err = time.ParseInLocation(formatTime, value, time.Local) } - if err != nil { return err }