Skip to content

Commit

Permalink
c.IsInvalid() -> c.Error != nil
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Apr 9, 2024
1 parent 8fa8d26 commit 1b97934
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func SetLocale(locale string) Carbon {
// SetDateTime sets year, month, day, hour, minute and second.
// 设置年、月、日、时、分、秒
func (c Carbon) SetDateTime(year, month, day, hour, minute, second int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
return c.create(year, month, day, hour, minute, second, c.Nanosecond())
Expand All @@ -89,7 +89,7 @@ func (c Carbon) SetDateTime(year, month, day, hour, minute, second int) Carbon {
// SetDateTimeMilli sets year, month, day, hour, minute, second and millisecond.
// 设置年、月、日、时、分、秒、毫秒
func (c Carbon) SetDateTimeMilli(year, month, day, hour, minute, second, millisecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
return c.create(year, month, day, hour, minute, second, millisecond*1e6)
Expand All @@ -98,7 +98,7 @@ func (c Carbon) SetDateTimeMilli(year, month, day, hour, minute, second, millise
// SetDateTimeMicro sets year, month, day, hour, minute, second and microsecond.
// 设置年、月、日、时、分、秒、微秒
func (c Carbon) SetDateTimeMicro(year, month, day, hour, minute, second, microsecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
return c.create(year, month, day, hour, minute, second, microsecond*1e3)
Expand All @@ -107,7 +107,7 @@ func (c Carbon) SetDateTimeMicro(year, month, day, hour, minute, second, microse
// SetDateTimeNano sets year, month, day, hour, minute, second and nanosecond.
// 设置年、月、日、时、分、秒、纳秒
func (c Carbon) SetDateTimeNano(year, month, day, hour, minute, second, nanosecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
return c.create(year, month, day, hour, minute, second, nanosecond)
Expand All @@ -116,7 +116,7 @@ func (c Carbon) SetDateTimeNano(year, month, day, hour, minute, second, nanoseco
// SetDate sets year, month and day.
// 设置年、月、日
func (c Carbon) SetDate(year, month, day int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
hour, minute, second := c.Time()
Expand All @@ -126,7 +126,7 @@ func (c Carbon) SetDate(year, month, day int) Carbon {
// SetDateMilli sets year, month, day and millisecond.
// 设置年、月、日、毫秒
func (c Carbon) SetDateMilli(year, month, day, millisecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
hour, minute, second := c.Time()
Expand All @@ -136,7 +136,7 @@ func (c Carbon) SetDateMilli(year, month, day, millisecond int) Carbon {
// SetDateMicro sets year, month, day and microsecond.
// 设置年、月、日、微秒
func (c Carbon) SetDateMicro(year, month, day, microsecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
hour, minute, second := c.Time()
Expand All @@ -146,7 +146,7 @@ func (c Carbon) SetDateMicro(year, month, day, microsecond int) Carbon {
// SetDateNano sets year, month, day and nanosecond.
// 设置年、月、日、纳秒
func (c Carbon) SetDateNano(year, month, day, nanosecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
hour, minute, second := c.Time()
Expand All @@ -156,7 +156,7 @@ func (c Carbon) SetDateNano(year, month, day, nanosecond int) Carbon {
// SetTime sets hour, minute and second.
// 设置时、分、秒
func (c Carbon) SetTime(hour, minute, second int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day := c.Date()
Expand All @@ -166,7 +166,7 @@ func (c Carbon) SetTime(hour, minute, second int) Carbon {
// SetTimeMilli sets hour, minute, second and millisecond.
// 设置时、分、秒、毫秒
func (c Carbon) SetTimeMilli(hour, minute, second, millisecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day := c.Date()
Expand All @@ -176,7 +176,7 @@ func (c Carbon) SetTimeMilli(hour, minute, second, millisecond int) Carbon {
// SetTimeMicro sets hour, minute, second and microsecond.
// 设置时、分、秒、微秒
func (c Carbon) SetTimeMicro(hour, minute, second, microsecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day := c.Date()
Expand All @@ -186,7 +186,7 @@ func (c Carbon) SetTimeMicro(hour, minute, second, microsecond int) Carbon {
// SetTimeNano sets hour, minute, second and nanosecond.
// 设置、时、分、秒、纳秒
func (c Carbon) SetTimeNano(hour, minute, second, nanosecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day := c.Date()
Expand All @@ -196,7 +196,7 @@ func (c Carbon) SetTimeNano(hour, minute, second, nanosecond int) Carbon {
// SetYear sets year.
// 设置年份
func (c Carbon) SetYear(year int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
_, month, day, hour, minute, second := c.DateTime()
Expand All @@ -206,7 +206,7 @@ func (c Carbon) SetYear(year int) Carbon {
// SetYearNoOverflow sets year without overflowing month.
// 设置年份(月份不溢出)
func (c Carbon) SetYearNoOverflow(year int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
return c.AddYearsNoOverflow(year - c.Year())
Expand All @@ -215,7 +215,7 @@ func (c Carbon) SetYearNoOverflow(year int) Carbon {
// SetMonth sets month.
// 设置月份
func (c Carbon) SetMonth(month int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, _, day, hour, minute, second := c.DateTime()
Expand All @@ -225,7 +225,7 @@ func (c Carbon) SetMonth(month int) Carbon {
// SetMonthNoOverflow sets month without overflowing month.
// 设置月份(月份不溢出)
func (c Carbon) SetMonthNoOverflow(month int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
return c.AddMonthsNoOverflow(month - c.Month())
Expand All @@ -234,7 +234,7 @@ func (c Carbon) SetMonthNoOverflow(month int) Carbon {
// SetDay sets day.
// 设置日期
func (c Carbon) SetDay(day int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, _, hour, minute, second := c.DateTime()
Expand All @@ -244,7 +244,7 @@ func (c Carbon) SetDay(day int) Carbon {
// SetHour sets hour.
// 设置小时
func (c Carbon) SetHour(hour int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day, _, minute, second := c.DateTime()
Expand All @@ -254,7 +254,7 @@ func (c Carbon) SetHour(hour int) Carbon {
// SetMinute sets minute.
// 设置分钟
func (c Carbon) SetMinute(minute int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day, hour, _, second := c.DateTime()
Expand All @@ -264,7 +264,7 @@ func (c Carbon) SetMinute(minute int) Carbon {
// SetSecond sets second.
// 设置秒数
func (c Carbon) SetSecond(second int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day, hour, minute, _ := c.DateTime()
Expand All @@ -274,7 +274,7 @@ func (c Carbon) SetSecond(second int) Carbon {
// SetMillisecond sets millisecond.
// 设置毫秒
func (c Carbon) SetMillisecond(millisecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day, hour, minute, second := c.DateTime()
Expand All @@ -284,7 +284,7 @@ func (c Carbon) SetMillisecond(millisecond int) Carbon {
// SetMicrosecond sets microsecond.
// 设置微秒
func (c Carbon) SetMicrosecond(microsecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day, hour, minute, second := c.DateTime()
Expand All @@ -294,7 +294,7 @@ func (c Carbon) SetMicrosecond(microsecond int) Carbon {
// SetNanosecond sets nanosecond.
// 设置纳秒
func (c Carbon) SetNanosecond(nanosecond int) Carbon {
if c.IsInvalid() {
if c.Error != nil {
return c
}
year, month, day, hour, minute, second := c.DateTime()
Expand Down

0 comments on commit 1b97934

Please sign in to comment.