Skip to content

Commit dba6483

Browse files
committed
refactor: Optimize variable declaration and assignment
1 parent 9285d60 commit dba6483

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

helper.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,38 @@ func format2layout(format string) string {
107107

108108
// parses a timezone string as a time.Location instance.
109109
// 将 时区字符串 解析成 time.Location 实例
110-
func parseTimezone(timezone string) (*Location, error) {
110+
func parseTimezone(timezone string) (loc *Location, err error) {
111111
if timezone == "" {
112112
return nil, ErrEmptyTimezone()
113113
}
114-
loc, err := time.LoadLocation(timezone)
114+
loc, err = time.LoadLocation(timezone)
115115
if err != nil {
116116
err = fmt.Errorf("%w: %w", ErrInvalidTimezone(timezone), err)
117117
}
118-
return loc, err
118+
return
119119
}
120120

121121
// parses a duration string as a time.Duration instance.
122122
// 将 时长字符串 解析成 time.Duration 实例
123-
func parseDuration(duration string) (Duration, error) {
123+
func parseDuration(duration string) (dur Duration, err error) {
124124
if duration == "" {
125125
return 0, ErrEmptyDuration()
126126
}
127-
dur, err := time.ParseDuration(duration)
127+
dur, err = time.ParseDuration(duration)
128128
if err != nil {
129129
err = fmt.Errorf("%w: %w", ErrInvalidDuration(duration), err)
130130
}
131-
return dur, err
131+
return
132132
}
133133

134134
// parses a timestamp string as a int64 format timestamp.
135135
// 将 时间戳字符串 解析成 int64 格式时间戳
136-
func parseTimestamp(timestamp string) (int64, error) {
137-
ts, err := strconv.ParseInt(timestamp, 10, 64)
136+
func parseTimestamp(timestamp string) (ts int64, err error) {
137+
ts, err = strconv.ParseInt(timestamp, 10, 64)
138138
if err != nil {
139139
return 0, fmt.Errorf("%w: %w", ErrInvalidTimestamp(timestamp), err)
140140
}
141-
return ts, nil
141+
return
142142
}
143143

144144
// gets absolute value.

type_carbon.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ func (c *Carbon) Scan(src any) error {
1616
*c = *Parse(string(v), DefaultTimezone)
1717
case string:
1818
*c = *Parse(v, DefaultTimezone)
19-
case time.Time:
20-
*c = *CreateFromStdTime(v, DefaultTimezone)
2119
case int64:
2220
*c = *CreateFromTimestamp(v, DefaultTimezone)
21+
case time.Time:
22+
*c = *CreateFromStdTime(v, DefaultTimezone)
2323
default:
2424
return ErrFailedScan(v)
2525
}

type_format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func (t *FormatType[T]) Scan(src any) error {
3838
c = Parse(string(v), DefaultTimezone)
3939
case string:
4040
c = Parse(v, DefaultTimezone)
41-
case time.Time:
42-
c = CreateFromStdTime(v, DefaultTimezone)
4341
case int64:
4442
c = CreateFromTimestamp(v, DefaultTimezone)
43+
case time.Time:
44+
c = CreateFromStdTime(v, DefaultTimezone)
4545
default:
4646
return ErrFailedScan(v)
4747
}

type_layout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func (t *LayoutType[T]) Scan(src any) error {
3838
c = Parse(string(v), DefaultTimezone)
3939
case string:
4040
c = Parse(v, DefaultTimezone)
41-
case time.Time:
42-
c = CreateFromStdTime(v, DefaultTimezone)
4341
case int64:
4442
c = CreateFromTimestamp(v, DefaultTimezone)
43+
case time.Time:
44+
c = CreateFromStdTime(v, DefaultTimezone)
4545
default:
4646
return ErrFailedScan(v)
4747
}

0 commit comments

Comments
 (0)