MCPcopy
hub / github.com/pocketbase/pocketbase / ValidateValue

Method ValidateValue

core/field_date.go:122–148  ·  view source on GitHub ↗

ValidateValue implements [Field.ValidateValue] interface method.

(ctx context.Context, app App, record *Record)

Source from the content-addressed store, hash-verified

120
121// ValidateValue implements [Field.ValidateValue] interface method.
122func (f *DateField) ValidateValue(ctx context.Context, app App, record *Record) error {
123 val, ok := record.GetRaw(f.Name).(types.DateTime)
124 if !ok {
125 return validators.ErrUnsupportedValueType
126 }
127
128 if val.IsZero() {
129 if f.Required {
130 return validation.ErrRequired
131 }
132 return nil // nothing to check
133 }
134
135 if !f.Min.IsZero() {
136 if err := validation.Min(f.Min.Time()).Validate(val.Time()); err != nil {
137 return err
138 }
139 }
140
141 if !f.Max.IsZero() {
142 if err := validation.Max(f.Max.Time()).Validate(val.Time()); err != nil {
143 return err
144 }
145 }
146
147 return nil
148}
149
150// ValidateSettings implements [Field.ValidateSettings] interface method.
151func (f *DateField) ValidateSettings(ctx context.Context, app App, collection *Collection) error {

Callers

nothing calls this directly

Calls 4

GetRawMethod · 0.80
IsZeroMethod · 0.80
TimeMethod · 0.80
ValidateMethod · 0.65

Tested by

no test coverage detected