Skip to content

Commit ccc7974

Browse files
committed
refactor: Modify the Now function to return a copy of testNow to prevent external modifications from affecting testing time
1 parent d929030 commit ccc7974

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

traveler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// 当前
99
func Now(timezone ...string) *Carbon {
1010
if IsTestNow() {
11-
return frozenNow.testNow
11+
return frozenNow.testNow.Copy()
1212
}
1313
var (
1414
tz string
@@ -33,7 +33,7 @@ func Tomorrow(timezone ...string) *Carbon {
3333
if now.IsInvalid() {
3434
return now
3535
}
36-
return now.Copy().AddDay()
36+
return now.AddDay()
3737
}
3838

3939
// Yesterday returns a Carbon instance for yesterday.
@@ -43,7 +43,7 @@ func Yesterday(timezone ...string) *Carbon {
4343
if now.IsInvalid() {
4444
return now
4545
}
46-
return now.Copy().SubDay()
46+
return now.SubDay()
4747
}
4848

4949
// AddDuration adds duration.

0 commit comments

Comments
 (0)