mirror of
https://gitee.com/dromara/carbon.git
synced 2024-12-02 04:07:36 +08:00
优化 ParseByLayout
方法
This commit is contained in:
parent
0558b9d3e9
commit
f6452c93a4
@ -59,15 +59,16 @@ func ParseByFormat(value, format string, timezone ...string) Carbon {
|
||||
// ParseByLayout parses a time string as a Carbon instance by layout.
|
||||
// 通过布局模板将时间字符串解析成 Carbon 实例
|
||||
func (c Carbon) ParseByLayout(value, layout string, timezone ...string) Carbon {
|
||||
if len(value) == 0 {
|
||||
c.Error = invalidValueError(value)
|
||||
return c
|
||||
}
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.Error != nil {
|
||||
return c
|
||||
}
|
||||
if len(value) == 0 {
|
||||
return c
|
||||
}
|
||||
if len(layout) == 0 {
|
||||
layout = defaultLayout
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ func TestCarbon_Issue232(t *testing.T) {
|
||||
{
|
||||
name: "case1",
|
||||
carbon: Parse("0000-01-01 00:00:00"),
|
||||
want: "0000-01-01 00:00:00",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "case2",
|
||||
|
Loading…
Reference in New Issue
Block a user