mirror of
https://gitee.com/dromara/carbon.git
synced 2024-12-02 04:07:36 +08:00
Optimize code
This commit is contained in:
parent
5f1be6ac1c
commit
aae4528de8
11
parser.go
11
parser.go
@ -33,11 +33,12 @@ func (c Carbon) Parse(value string, timezone ...string) Carbon {
|
||||
layout = ShortDateTimeFormat
|
||||
}
|
||||
}
|
||||
if c.ParseByLayout(value, layout).Error != nil {
|
||||
c = c.ParseByLayout(value, layout)
|
||||
if c.Error != nil {
|
||||
c.Error = invalidValueError(value)
|
||||
return c
|
||||
}
|
||||
return c.ParseByLayout(value, layout)
|
||||
return c
|
||||
}
|
||||
|
||||
// Parse parses a standard string as a Carbon instance.
|
||||
@ -58,12 +59,12 @@ func (c Carbon) ParseByFormat(value string, format string, timezone ...string) C
|
||||
if value == "" || value == "0" || value == "0000-00-00 00:00:00" || value == "0000-00-00" || value == "00:00:00" {
|
||||
return c
|
||||
}
|
||||
layout := format2layout(format)
|
||||
if c.ParseByLayout(value, layout).Error != nil {
|
||||
c = c.ParseByLayout(value, format2layout(format))
|
||||
if c.Error != nil {
|
||||
c.Error = invalidFormatError(value, format)
|
||||
return c
|
||||
}
|
||||
return c.ParseByLayout(value, layout)
|
||||
return c
|
||||
}
|
||||
|
||||
// ParseByFormat parses a string as a Carbon instance by format.
|
||||
|
Loading…
Reference in New Issue
Block a user