MCPcopy
hub / github.com/pocketbase/pocketbase / TestDateTimeScan

Function TestDateTimeScan

tools/types/datetime_test.go:386–417  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

384}
385
386func TestDateTimeScan(t *testing.T) {
387 now := time.Now().UTC().Format("2006-01-02 15:04:05") // without ms part for test consistency
388
389 scenarios := []struct {
390 value any
391 expected string
392 }{
393 {nil, ""},
394 {"", ""},
395 {"invalid", ""},
396 {types.NowDateTime(), now},
397 {time.Now(), now},
398 {1.0, ""},
399 {1641024040, "2022-01-01 08:00:40.000Z"},
400 {"2022-01-01 11:23:45.678", "2022-01-01 11:23:45.678Z"},
401 }
402
403 for i, s := range scenarios {
404 t.Run(fmt.Sprintf("%d_%#v", i, s.value), func(t *testing.T) {
405 dt := types.DateTime{}
406
407 err := dt.Scan(s.value)
408 if err != nil {
409 t.Fatalf("Failed to parse %v: %v", s.value, err)
410 }
411
412 if !strings.Contains(dt.String(), s.expected) {
413 t.Fatalf("Expected %q, got %q", s.expected, dt.String())
414 }
415 })
416 }
417}

Callers

nothing calls this directly

Calls 4

ScanMethod · 0.95
StringMethod · 0.95
NowDateTimeFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…