@@ -69,15 +69,19 @@ type FooStructDisallowUnknownFields struct {
6969}
7070
7171type FooBarStructForTimeType struct {
72- TimeFoo time.Time `form:"time_foo" time_format:"2006-01-02" time_utc:"1" time_location:"Asia/Chongqing"`
73- TimeBar time.Time `form:"time_bar" time_format:"2006-01-02" time_utc:"1"`
74- CreateTime time.Time `form:"createTime" time_format:"unixNano"`
75- UnixTime time.Time `form:"unixTime" time_format:"unix"`
72+ TimeFoo time.Time `form:"time_foo" time_format:"2006-01-02" time_utc:"1" time_location:"Asia/Chongqing"`
73+ TimeBar time.Time `form:"time_bar" time_format:"2006-01-02" time_utc:"1"`
74+ CreateTime time.Time `form:"createTime" time_format:"unixNano"`
75+ UnixTime time.Time `form:"unixTime" time_format:"unix"`
76+ UnixMilliTime time.Time `form:"unixMilliTime" time_format:"unixmilli"`
77+ UnixMicroTime time.Time `form:"unixMicroTime" time_format:"uNiXmiCrO"`
7678}
7779
7880type FooStructForTimeTypeNotUnixFormat struct {
79- CreateTime time.Time `form:"createTime" time_format:"unixNano"`
80- UnixTime time.Time `form:"unixTime" time_format:"unix"`
81+ CreateTime time.Time `form:"createTime" time_format:"unixNano"`
82+ UnixTime time.Time `form:"unixTime" time_format:"unix"`
83+ UnixMilliTime time.Time `form:"unixMilliTime" time_format:"unixMilli"`
84+ UnixMicroTime time.Time `form:"unixMicroTime" time_format:"unixMicro"`
8185}
8286
8387type FooStructForTimeTypeNotFormat struct {
@@ -265,10 +269,10 @@ func TestBindingFormDefaultValue2(t *testing.T) {
265269func TestBindingFormForTime (t * testing.T ) {
266270 testFormBindingForTime (t , http .MethodPost ,
267271 "/" , "/" ,
268- "time_foo=2017-11-15&time_bar=&createTime=1562400033000000123&unixTime=1562400033" , "bar2=foo" )
272+ "time_foo=2017-11-15&time_bar=&createTime=1562400033000000123&unixTime=1562400033&unixMilliTime=1562400033001&unixMicroTime=1562400033000012 " , "bar2=foo" )
269273 testFormBindingForTimeNotUnixFormat (t , http .MethodPost ,
270274 "/" , "/" ,
271- "time_foo=2017-11-15&createTime=bad&unixTime=bad" , "bar2=foo" )
275+ "time_foo=2017-11-15&createTime=bad&unixTime=bad&unixMilliTime=bad&unixMicroTime=bad " , "bar2=foo" )
272276 testFormBindingForTimeNotFormat (t , http .MethodPost ,
273277 "/" , "/" ,
274278 "time_foo=2017-11-15" , "bar2=foo" )
@@ -282,11 +286,11 @@ func TestBindingFormForTime(t *testing.T) {
282286
283287func TestBindingFormForTime2 (t * testing.T ) {
284288 testFormBindingForTime (t , http .MethodGet ,
285- "/?time_foo=2017-11-15&time_bar=&createTime=1562400033000000123&unixTime=1562400033" , "/?bar2=foo" ,
289+ "/?time_foo=2017-11-15&time_bar=&createTime=1562400033000000123&unixTime=1562400033&unixMilliTime=1562400033001&unixMicroTime=1562400033000012 " , "/?bar2=foo" ,
286290 "" , "" )
287291 testFormBindingForTimeNotUnixFormat (t , http .MethodPost ,
288292 "/" , "/" ,
289- "time_foo=2017-11-15&createTime=bad&unixTime=bad" , "bar2=foo" )
293+ "time_foo=2017-11-15&createTime=bad&unixTime=bad&unixMilliTime=bad&unixMicroTime=bad " , "bar2=foo" )
290294 testFormBindingForTimeNotFormat (t , http .MethodGet ,
291295 "/?time_foo=2017-11-15" , "/?bar2=foo" ,
292296 "" , "" )
@@ -952,6 +956,8 @@ func testFormBindingForTime(t *testing.T, method, path, badPath, body, badBody s
952956 assert .Equal (t , "UTC" , obj .TimeBar .Location ().String ())
953957 assert .Equal (t , int64 (1562400033000000123 ), obj .CreateTime .UnixNano ())
954958 assert .Equal (t , int64 (1562400033 ), obj .UnixTime .Unix ())
959+ assert .Equal (t , int64 (1562400033001 ), obj .UnixMilliTime .UnixMilli ())
960+ assert .Equal (t , int64 (1562400033000012 ), obj .UnixMicroTime .UnixMicro ())
955961
956962 obj = FooBarStructForTimeType {}
957963 req = requestWithBody (method , badPath , badBody )
0 commit comments