MCPcopy Index your code
hub / github.com/labstack/echo / TestParseValue_Time

Function TestParseValue_Time

binder_generic_test.go:1123–1239  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1121}
1122
1123func TestParseValue_Time(t *testing.T) {
1124 tallinn, err := time.LoadLocation("Europe/Tallinn")
1125 if err != nil {
1126 t.Fatal(err)
1127 }
1128 berlin, err := time.LoadLocation("Europe/Berlin")
1129 if err != nil {
1130 t.Fatal(err)
1131 }
1132
1133 parse := func(t *testing.T, layout string, s string) time.Time {
1134 result, err := time.Parse(layout, s)
1135 if err != nil {
1136 t.Fatal(err)
1137 }
1138 return result
1139 }
1140
1141 parseInLoc := func(t *testing.T, layout string, s string, loc *time.Location) time.Time {
1142 result, err := time.ParseInLocation(layout, s, loc)
1143 if err != nil {
1144 t.Fatal(err)
1145 }
1146 return result
1147 }
1148
1149 var testCases = []struct {
1150 name string
1151 when string
1152 whenLayout TimeLayout
1153 whenTimeOpts *TimeOpts
1154 expect time.Time
1155 expectErr string
1156 }{
1157 {
1158 name: "ok, defaults to RFC3339Nano",
1159 when: "2006-01-02T15:04:05.999999999Z",
1160 expect: parse(t, time.RFC3339Nano, "2006-01-02T15:04:05.999999999Z"),
1161 },
1162 {
1163 name: "ok, custom TimeOpt",
1164 when: "2006-01-02",
1165 whenTimeOpts: &TimeOpts{
1166 Layout: time.DateOnly,
1167 ParseInLocation: tallinn,
1168 ToInLocation: berlin,
1169 },
1170 expect: parseInLoc(t, time.DateTime, "2006-01-01 23:00:00", berlin),
1171 },
1172 {
1173 name: "ok, custom layout",
1174 when: "2006-01-02",
1175 whenLayout: TimeLayout(time.DateOnly),
1176 expect: parse(t, time.DateOnly, "2006-01-02"),
1177 },
1178 {
1179 name: "ok, TimeLayoutUnixTime",
1180 when: "1766604665",

Callers

nothing calls this directly

Calls 2

TimeLayoutTypeAlias · 0.85
ParseValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…