@@ -10,9 +10,7 @@ import (
10
10
// 将标准格式时间字符串解析成 Carbon 实例
11
11
func (c Carbon ) Parse (value string , timezone ... string ) Carbon {
12
12
if len (timezone ) > 0 {
13
- loc , err := getLocationByTimezone (timezone [len (timezone )- 1 ])
14
- c .Loc = loc
15
- c .Error = err
13
+ c .loc , c .Error = getLocationByTimezone (timezone [len (timezone )- 1 ])
16
14
}
17
15
if c .Error != nil {
18
16
return c
@@ -52,9 +50,7 @@ func Parse(value string, timezone ...string) Carbon {
52
50
// 通过格式化字符将字符串解析成 carbon 实例
53
51
func (c Carbon ) ParseByFormat (value string , format string , timezone ... string ) Carbon {
54
52
if len (timezone ) > 0 {
55
- loc , err := getLocationByTimezone (timezone [len (timezone )- 1 ])
56
- c .Loc = loc
57
- c .Error = err
53
+ c .loc , c .Error = getLocationByTimezone (timezone [len (timezone )- 1 ])
58
54
}
59
55
if c .Error != nil {
60
56
return c
@@ -80,17 +76,15 @@ func ParseByFormat(value string, format string, timezone ...string) Carbon {
80
76
// 通过布局字符将字符串解析成 carbon 实例
81
77
func (c Carbon ) ParseByLayout (value string , layout string , timezone ... string ) Carbon {
82
78
if len (timezone ) > 0 {
83
- loc , err := getLocationByTimezone (timezone [len (timezone )- 1 ])
84
- c .Loc = loc
85
- c .Error = err
79
+ c .loc , c .Error = getLocationByTimezone (timezone [len (timezone )- 1 ])
86
80
}
87
81
if c .Error != nil {
88
82
return c
89
83
}
90
84
if value == "" || value == "0" || value == "0000-00-00 00:00:00" || value == "0000-00-00" || value == "00:00:00" {
91
85
return c
92
86
}
93
- tt , err := time .ParseInLocation (layout , value , c .Loc )
87
+ tt , err := time .ParseInLocation (layout , value , c .loc )
94
88
if err != nil {
95
89
c .Error = invalidLayoutError (value , layout )
96
90
return c
0 commit comments