Ai
1 Star 1 Fork 1

c./goframe框架

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
builtin_date.go 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
admin 提交于 2024-11-08 04:16 +08:00 . 2024-11-7
// 版权归GoFrame作者(https://goframe.org)所有。保留所有权利。
//
// 本源代码形式受MIT许可证条款约束。
// 如果未随本文件一同分发MIT许可证副本,
// 您可以在https://github.com/gogf/gf处获取。
// md5:a9832f33b234e3f3
package builtin
import (
"errors"
"time"
gregex "gitee.com/go_888/goframe/text/gregex"
)
// RuleDate 实现了 `date` 规则:
// 标准日期格式,例如:2006-01-02, 20060102, 2006.01.02。
//
// 格式:date
// md5:91044156fb254923
type RuleDate struct{}
func init() {
Register(RuleDate{})
}
func (r RuleDate) Name() string {
return "date"
}
func (r RuleDate) Message() string {
return "{field}字段值`{value}`日期格式不满足Y-m-d格式,例如: 2001-02-03"
}
func (r RuleDate) Run(in RunInput) error {
type iTime interface {
Date() (year int, month time.Month, day int)
IsZero() bool
}
// 支持时间值,例如:gtime.Time/*gtime.Time, time.Time/*time.Time。 md5:fc74717f7b27de8d
if obj, ok := in.Value.X取值().(iTime); ok {
if obj.IsZero() {
return errors.New(in.Message)
}
}
if !gregex.X是否匹配文本(
`\d{4}[\.\-\_/]{0,1}\d{2}[\.\-\_/]{0,1}\d{2}`,
in.Value.String(),
) {
return errors.New(in.Message)
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go_888/goframe.git
git@gitee.com:go_888/goframe.git
go_888
goframe
goframe框架
782a3f7170cf

搜索帮助