MCPcopy
hub / github.com/pocketbase/pocketbase / Scan

Method Scan

tools/types/datetime.go:129–158  ·  view source on GitHub ↗

Scan implements [sql.Scanner] interface to scan the provided value into the current DateTime instance.

(value any)

Source from the content-addressed store, hash-verified

127// Scan implements [sql.Scanner] interface to scan the provided value
128// into the current DateTime instance.
129func (d *DateTime) Scan(value any) error {
130 switch v := value.(type) {
131 case time.Time:
132 d.t = v
133 case DateTime:
134 d.t = v.Time()
135 case string:
136 if v == "" {
137 d.t = time.Time{}
138 } else {
139 t, err := time.Parse(DefaultDateLayout, v)
140 if err != nil {
141 // check for other common date layouts
142 t = cast.ToTime(v)
143 }
144 d.t = t
145 }
146 case int, int64, int32, uint, uint64, uint32:
147 d.t = cast.ToTime(v)
148 default:
149 str := cast.ToString(v)
150 if str == "" {
151 d.t = time.Time{}
152 } else {
153 d.t = cast.ToTime(str)
154 }
155 }
156
157 return nil
158}

Callers 3

ParseDateTimeFunction · 0.95
UnmarshalJSONMethod · 0.95
TestDateTimeScanFunction · 0.95

Calls 2

TimeMethod · 0.80
ParseMethod · 0.80

Tested by 1

TestDateTimeScanFunction · 0.76