@@ -183,30 +183,36 @@ func TestMapFormWithTag(t *testing.T) {
183183
184184func TestMappingTime (t * testing.T ) {
185185 var s struct {
186- Time time.Time
187- LocalTime time.Time `time_format:"2006-01-02"`
188- ZeroValue time.Time
189- CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`
190- UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"`
186+ Time time.Time
187+ LocalTime time.Time `time_format:"2006-01-02"`
188+ ZeroValue time.Time
189+ ZeroUnixTime time.Time `time_format:"unix"`
190+ ZeroUnixNanoTime time.Time `time_format:"unixnano"`
191+ CSTTime time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`
192+ UTCTime time.Time `time_format:"2006-01-02" time_utc:"1"`
191193 }
192194
193195 var err error
194196 time .Local , err = time .LoadLocation ("Europe/Berlin" )
195197 require .NoError (t , err )
196198
197199 err = mapForm (& s , map [string ][]string {
198- "Time" : {"2019-01-20T16:02:58Z" },
199- "LocalTime" : {"2019-01-20" },
200- "ZeroValue" : {},
201- "CSTTime" : {"2019-01-20" },
202- "UTCTime" : {"2019-01-20" },
200+ "Time" : {"2019-01-20T16:02:58Z" },
201+ "LocalTime" : {"2019-01-20" },
202+ "ZeroValue" : {},
203+ "ZeroUnixTime" : {},
204+ "ZeroUnixNanoTime" : {},
205+ "CSTTime" : {"2019-01-20" },
206+ "UTCTime" : {"2019-01-20" },
203207 })
204208 require .NoError (t , err )
205209
206210 assert .Equal (t , "2019-01-20 16:02:58 +0000 UTC" , s .Time .String ())
207211 assert .Equal (t , "2019-01-20 00:00:00 +0100 CET" , s .LocalTime .String ())
208212 assert .Equal (t , "2019-01-19 23:00:00 +0000 UTC" , s .LocalTime .UTC ().String ())
209213 assert .Equal (t , "0001-01-01 00:00:00 +0000 UTC" , s .ZeroValue .String ())
214+ assert .Equal (t , "1970-01-01 00:00:00 +0000 UTC" , s .ZeroUnixTime .UTC ().String ())
215+ assert .Equal (t , "1970-01-01 00:00:00 +0000 UTC" , s .ZeroUnixNanoTime .UTC ().String ())
210216 assert .Equal (t , "2019-01-20 00:00:00 +0800 CST" , s .CSTTime .String ())
211217 assert .Equal (t , "2019-01-19 16:00:00 +0000 UTC" , s .CSTTime .UTC ().String ())
212218 assert .Equal (t , "2019-01-20 00:00:00 +0000 UTC" , s .UTCTime .String ())
0 commit comments