From 9e5266dca913faee00908635543925306b445b6d Mon Sep 17 00:00:00 2001 From: Peleus <245629560@qq.com> Date: Tue, 9 Apr 2024 20:03:40 +0800 Subject: [PATCH] Treat empty value as an error --- parser.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parser.go b/parser.go index ec286913..647de9fe 100755 --- a/parser.go +++ b/parser.go @@ -8,7 +8,8 @@ import ( // Parse parses a standard time string as a Carbon instance. // 将标准格式时间字符串解析成 Carbon 实例 func (c Carbon) Parse(value string, timezone ...string) Carbon { - if value == "" || value == "0" || value == "0000-00-00 00:00:00" || value == "0000-00-00" || value == "00:00:00" { + if value == "" { + c.Error = invalidValueError(value) return c } if len(timezone) > 0 { @@ -64,7 +65,7 @@ func (c Carbon) ParseByLayout(value, layout string, timezone ...string) Carbon { if c.Error != nil { return c } - if value == "" || value == "0" || value == "0000-00-00 00:00:00" || value == "0000-00-00" || value == "00:00:00" { + if value == "" { return c } if layout == "timestamp" {