Time scanner.

This commit is contained in:
Nuno Cruces
2023-10-17 23:52:04 +01:00
parent 8d0c654178
commit d4ff605983
2 changed files with 49 additions and 0 deletions

16
time.go
View File

@@ -338,3 +338,19 @@ func (f TimeFormat) parseRelaxed(s string) (time.Time, error) {
}
return t, nil
}
// Scanner returns a [database/sql.Scanner] that
// decodes a time value into dest using this format.
func (f TimeFormat) Scanner(dest *time.Time) interface{ Scan(any) error } {
return timeScanner{dest, f}
}
type timeScanner struct {
*time.Time
TimeFormat
}
func (s timeScanner) Scan(src any) (err error) {
*s.Time, err = s.Decode(src)
return
}