Skip to content

Commit

Permalink
The public fields Loc and Lang in the carbon structure are changed to…
Browse files Browse the repository at this point in the history
… private fields loc and lang
  • Loading branch information
gouguoyin committed Aug 16, 2021
1 parent f8d3bab commit b2e5808
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions season.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func (c Carbon) Season() string {
if c.IsInvalid() {
return ""
}
if len(c.Lang.resources) == 0 {
c.Lang.SetLocale(defaultLocale)
if len(c.lang.resources) == 0 {
c.lang.SetLocale(defaultLocale)
}
index := -1
switch {
Expand All @@ -25,7 +25,7 @@ func (c Carbon) Season() string {
case c.Month() == 12 || c.Month() == 1 || c.Month() == 2:
index = 3
}
if seasons, ok := c.Lang.resources["seasons"]; ok {
if seasons, ok := c.lang.resources["seasons"]; ok {
slice := strings.Split(seasons, "|")
if len(slice) == 4 {
return slice[index]
Expand All @@ -41,10 +41,10 @@ func (c Carbon) StartOfSeason() Carbon {
return c
}
if c.Month() == 1 || c.Month() == 2 {
c.Time = time.Date(c.Year()-1, time.Month(12), 1, 0, 0, 0, 0, c.Loc)
c.Time = time.Date(c.Year()-1, time.Month(12), 1, 0, 0, 0, 0, c.loc)
return c
}
c.Time = time.Date(c.Year(), time.Month(c.Month()/3*3), 1, 0, 0, 0, 0, c.Loc)
c.Time = time.Date(c.Year(), time.Month(c.Month()/3*3), 1, 0, 0, 0, 0, c.loc)
return c
}

Expand All @@ -55,14 +55,14 @@ func (c Carbon) EndOfSeason() Carbon {
return c
}
if c.Month() == 1 || c.Month() == 2 {
c.Time = time.Date(c.Year(), time.Month(2), 1, 23, 59, 59, 999999999, c.Loc).AddDate(0, 1, -1)
c.Time = time.Date(c.Year(), time.Month(2), 1, 23, 59, 59, 999999999, c.loc).AddDate(0, 1, -1)
return c
}
if c.Month() == 12 {
c.Time = time.Date(c.Year()+1, time.Month(2), 1, 23, 59, 59, 999999999, c.Loc).AddDate(0, 1, -1)
c.Time = time.Date(c.Year()+1, time.Month(2), 1, 23, 59, 59, 999999999, c.loc).AddDate(0, 1, -1)
return c
}
c.Time = time.Date(c.Year(), time.Month(c.Month()/3*3+2), 1, 23, 59, 59, 999999999, c.Loc).AddDate(0, 1, -1)
c.Time = time.Date(c.Year(), time.Month(c.Month()/3*3+2), 1, 23, 59, 59, 999999999, c.loc).AddDate(0, 1, -1)
return c
}

Expand Down
18 changes: 9 additions & 9 deletions traveler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (c Carbon) AddDuration(duration string) Carbon {
return c
}
td, err := parseByDuration(duration)
c.Time = c.Time.In(c.Loc).Add(td)
c.Time = c.Time.In(c.loc).Add(td)
c.Error = err
return c
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func (c Carbon) AddYears(years int) Carbon {
if c.IsInvalid() {
return c
}
c.Time = c.Time.In(c.Loc).AddDate(years, 0, 0)
c.Time = c.Time.In(c.loc).AddDate(years, 0, 0)
return c
}

Expand All @@ -135,12 +135,12 @@ func (c Carbon) AddYearsNoOverflow(years int) Carbon {
return c
}
// 获取N年后本月的最后一天
last := time.Date(c.Year()+years, time.Month(c.Month()), 1, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc).AddDate(0, 1, -1)
last := time.Date(c.Year()+years, time.Month(c.Month()), 1, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc).AddDate(0, 1, -1)
day := c.Day()
if c.Day() > last.Day() {
day = last.Day()
}
c.Time = time.Date(last.Year(), last.Month(), day, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc)
c.Time = time.Date(last.Year(), last.Month(), day, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc)
return c
}

Expand Down Expand Up @@ -237,7 +237,7 @@ func (c Carbon) AddMonths(months int) Carbon {
if c.IsInvalid() {
return c
}
c.Time = c.Time.In(c.Loc).AddDate(0, months, 0)
c.Time = c.Time.In(c.loc).AddDate(0, months, 0)
return c
}

Expand All @@ -249,12 +249,12 @@ func (c Carbon) AddMonthsNoOverflow(months int) Carbon {
}
month := c.Month() + months
// 获取N月后的最后一天
last := time.Date(c.Year(), time.Month(month), 1, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc).AddDate(0, 1, -1)
last := time.Date(c.Year(), time.Month(month), 1, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc).AddDate(0, 1, -1)
day := c.Day()
if c.Day() > last.Day() {
day = last.Day()
}
c.Time = time.Date(last.Year(), last.Month(), day, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Loc)
c.Time = time.Date(last.Year(), last.Month(), day, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.loc)
return c
}

Expand Down Expand Up @@ -324,7 +324,7 @@ func (c Carbon) AddDays(days int) Carbon {
if c.IsInvalid() {
return c
}
c.Time = c.Time.In(c.Loc).AddDate(0, 0, days)
c.Time = c.Time.In(c.loc).AddDate(0, 0, days)
return c
}

Expand Down Expand Up @@ -353,7 +353,7 @@ func (c Carbon) AddHours(hours int) Carbon {
return c
}
td := time.Duration(hours) * time.Hour
c.Time = c.Time.In(c.Loc).Add(td)
c.Time = c.Time.In(c.loc).Add(td)
return c
}

Expand Down

0 comments on commit b2e5808

Please sign in to comment.