Skip to content

Commit

Permalink
Optimize the adaptation of testing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Aug 25, 2023
1 parent 110071a commit 81c1420
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions traveler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func (c Carbon) Now(timezone ...string) Carbon {
if c.Error != nil {
return c
}
if c.isTestNow && !c.IsZero() {
return c
}
c.time = time.Now().In(c.loc)
return c
}
Expand All @@ -32,12 +35,13 @@ func (c Carbon) Tomorrow(timezone ...string) Carbon {
if c.Error != nil {
return c
}
if c.IsZero() {
c.time = c.Now().time.In(c.loc).AddDate(0, 0, 1)
return c
if c.isTestNow {
return c.AddDay()
}
c.time = c.time.In(c.loc).AddDate(0, 0, 1)
return c
if !c.IsZero() {
return c.AddDay()
}
return c.Now().AddDay()
}

// Tomorrow returns a Carbon instance for tomorrow.
Expand All @@ -55,12 +59,13 @@ func (c Carbon) Yesterday(timezone ...string) Carbon {
if c.Error != nil {
return c
}
if c.IsZero() {
c.time = c.Now().time.In(c.loc).AddDate(0, 0, -1)
return c
if c.isTestNow {
return c.SubDay()
}
c.time = c.time.In(c.loc).AddDate(0, 0, -1)
return c
if !c.IsZero() {
return c.SubDay()
}
return c.Now().SubDay()
}

// Yesterday returns a Carbon instance for yesterday.
Expand Down

0 comments on commit 81c1420

Please sign in to comment.