/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
util/gvalid/internal/builtin/builtin_date_format.go
50 строк
1 KB
John Guo
feature/v2.2.0 (#2154)
26 сен 2022, 17:11
Не верифицирован
26 сен 2022, 17:11
141ca62
Код
Авторство
О чём код?
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package builtin import ( "errors" "time" "github.com/gogf/gf/v2/os/gtime" ) // RuleDateFormat implements `date-format` rule: // Custom date format. // // Format: date-format:format type RuleDateFormat struct{} func init() { Register(RuleDateFormat{}) } func (r RuleDateFormat) Name() string { return "date-format" } func (r RuleDateFormat) Message() string { return "The {field} value `{value}` does not match the format: {pattern}" } func (r RuleDateFormat) Run(in RunInput) error { type iTime interface { Date() (year int, month time.Month, day int) IsZero() bool } // support for time value, eg: gtime.Time/*gtime.Time, time.Time/*time.Time. if obj, ok := in.Value.Val().(iTime); ok { if obj.IsZero() { return errors.New(in.Message) } return nil } if _, err := gtime.StrToTimeFormat(in.Value.String(), in.RulePattern); err != nil { return errors.New(in.Message) } return nil }