aboutsummaryrefslogtreecommitdiff
path: root/src/time
diff options
context:
space:
mode:
authorbaycore <dxasu@qq.com>2025-10-27 04:43:32 +0000
committerKeith Randall <khr@google.com>2025-10-27 09:44:55 -0700
commit189f2c08cc769fdc98d28ec536010b6f119e645f (patch)
treec3fdcfc792efee12fd29f2b910951cd1900baa00 /src/time
parentf619b4a00d6a7ce2fbb84729cdfe764697cb2171 (diff)
downloadgo-189f2c08cc769fdc98d28ec536010b6f119e645f.tar.xz
time: rewrite IsZero method to use wall and ext fields
Using wall and ext fields will be more efficient. Fixes #76001 Change-Id: If2b9f597562e0d0d3f8ab300556fa559926480a0 GitHub-Last-Rev: 4a91948413079047cb6c382ed29844f456f3064d GitHub-Pull-Request: golang/go#76006 Reviewed-on: https://go-review.googlesource.com/c/go/+/713720 Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/time')
-rw-r--r--src/time/time.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/time/time.go b/src/time/time.go
index cf9abc7196..32a1ce4307 100644
--- a/src/time/time.go
+++ b/src/time/time.go
@@ -260,7 +260,11 @@ func (t *Time) mono() int64 {
// IsZero reports whether t represents the zero time instant,
// January 1, year 1, 00:00:00 UTC.
func (t Time) IsZero() bool {
- return t.sec() == 0 && t.nsec() == 0
+ // If hasMonotonic is set in t.wall, then the time can't be before 1885, so it can't be the year 1.
+ // If hasMonotonic is zero, then all the bits in wall other than the nanoseconds field should be 0.
+ // So if there are no nanoseconds then t.wall == 0, and if there are no seconds then t.ext == 0.
+ // This is equivalent to t.sec() == 0 && t.nsec() == 0, but is more efficient.
+ return t.wall == 0 && t.ext == 0
}
// After reports whether the time instant t is after u.