Home / Function/ TestMappingTime() — gin Function Reference

TestMappingTime() — gin Function Reference

Architecture documentation for the TestMappingTime() function in form_mapping_test.go from the gin codebase.

Entity Profile

Dependency Diagram

graph TD
  9d2f9b4b_041e_5d96_4e87_1498ef46a108["TestMappingTime()"]
  36de44f8_6a8c_78ab_4c20_59952e276c82["form_mapping_test.go"]
  9d2f9b4b_041e_5d96_4e87_1498ef46a108 -->|defined in| 36de44f8_6a8c_78ab_4c20_59952e276c82
  style 9d2f9b4b_041e_5d96_4e87_1498ef46a108 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binding/form_mapping_test.go lines 185–228

func TestMappingTime(t *testing.T) {
	var s struct {
		Time      time.Time
		LocalTime time.Time `time_format:"2006-01-02"`
		ZeroValue time.Time
		CSTTime   time.Time `time_format:"2006-01-02" time_location:"Asia/Shanghai"`
		UTCTime   time.Time `time_format:"2006-01-02" time_utc:"1"`
	}

	var err error
	time.Local, err = time.LoadLocation("Europe/Berlin")
	require.NoError(t, err)

	err = mapForm(&s, map[string][]string{
		"Time":      {"2019-01-20T16:02:58Z"},
		"LocalTime": {"2019-01-20"},
		"ZeroValue": {},
		"CSTTime":   {"2019-01-20"},
		"UTCTime":   {"2019-01-20"},
	})
	require.NoError(t, err)

	assert.Equal(t, "2019-01-20 16:02:58 +0000 UTC", s.Time.String())
	assert.Equal(t, "2019-01-20 00:00:00 +0100 CET", s.LocalTime.String())
	assert.Equal(t, "2019-01-19 23:00:00 +0000 UTC", s.LocalTime.UTC().String())
	assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", s.ZeroValue.String())
	assert.Equal(t, "2019-01-20 00:00:00 +0800 CST", s.CSTTime.String())
	assert.Equal(t, "2019-01-19 16:00:00 +0000 UTC", s.CSTTime.UTC().String())
	assert.Equal(t, "2019-01-20 00:00:00 +0000 UTC", s.UTCTime.String())

	// wrong location
	var wrongLoc struct {
		Time time.Time `time_location:"wrong"`
	}
	err = mapForm(&wrongLoc, map[string][]string{"Time": {"2019-01-20T16:02:58Z"}})
	require.Error(t, err)

	// wrong time value
	var wrongTime struct {
		Time time.Time
	}
	err = mapForm(&wrongTime, map[string][]string{"Time": {"wrong"}})
	require.Error(t, err)
}

Subdomains

Frequently Asked Questions

What does TestMappingTime() do?
TestMappingTime() is a function in the gin codebase, defined in binding/form_mapping_test.go.
Where is TestMappingTime() defined?
TestMappingTime() is defined in binding/form_mapping_test.go at line 185.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free