Skip to content

Commit

Permalink
Treat empty value as an error
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Apr 9, 2024
1 parent 51913ec commit 9e5266d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 9e5266d

Please sign in to comment.