MCPcopy
hub / github.com/mitchellh/mapstructure / StringToTimeHookFunc

Function StringToTimeHookFunc

decode_hooks.go:187–202  ·  view source on GitHub ↗

StringToTimeHookFunc returns a DecodeHookFunc that converts strings to time.Time.

(layout string)

Source from the content-addressed store, hash-verified

185// StringToTimeHookFunc returns a DecodeHookFunc that converts
186// strings to time.Time.
187func StringToTimeHookFunc(layout string) DecodeHookFunc {
188 return func(
189 f reflect.Type,
190 t reflect.Type,
191 data interface{}) (interface{}, error) {
192 if f.Kind() != reflect.String {
193 return data, nil
194 }
195 if t != reflect.TypeOf(time.Time{}) {
196 return data, nil
197 }
198
199 // Convert it by parsing
200 return time.Parse(layout, data.(string))
201 }
202}
203
204// WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to
205// the decoder.

Callers 1

TestStringToTimeHookFuncFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestStringToTimeHookFuncFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…