feat(12.2-01): add lagoon.Date and lagoon.TimeOfDay with Fill and required support

- Date (DATE) and TimeOfDay (TIME) with Scanner, Valuer, JSON and text forms
- Fill falls back to encoding.TextUnmarshaler for string sources after
  every existing conversion, so time.Time and the new types fill from JSON
- required treats a zero time.Time, Date or TimeOfDay as empty
- lagoon README, models and casts-and-validation docs
This commit is contained in:
Jakub Zych
2026-10-02 17:40:48 +02:00
parent 19f4cf8232
commit f48a886f94
7 changed files with 532 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"git.golem15.com/golem15/summercms/modules/phrasebook"
"github.com/go-playground/validator/v10"
@@ -265,6 +266,22 @@ func isEmptyValue(val any) bool {
if val == nil {
return true
}
// A zero time.Time, Date or TimeOfDay is "no value" for required. Only
// these three types are checked, so no other type's emptiness changes.
switch v := val.(type) {
case time.Time:
return v.IsZero()
case *time.Time:
return v == nil || v.IsZero()
case Date:
return v.IsZero()
case *Date:
return v == nil || v.IsZero()
case TimeOfDay:
return v.IsZero()
case *TimeOfDay:
return v == nil || v.IsZero()
}
rv := reflect.ValueOf(val)
switch rv.Kind() {
case reflect.Ptr, reflect.Interface: