Use time.Since rather than time.Now().Sub (#1160)
diff --git a/examples/derived_gauges/README.md b/examples/derived_gauges/README.md
index 8d6f0db..f811d1f 100644
--- a/examples/derived_gauges/README.md
+++ b/examples/derived_gauges/README.md
@@ -131,7 +131,7 @@
func (q *queue) Elapsed() float64 {
q.mu.Lock()
defer q.mu.Unlock()
- return time.Now().Sub(q.lastConsumed).Seconds()
+ return time.Since(q.lastConsumed).Seconds()
}
```
@@ -254,7 +254,7 @@
func (q *queue) Elapsed() float64 {
q.mu.Lock()
defer q.mu.Unlock()
- return time.Now().Sub(q.lastConsumed).Seconds()
+ return time.Since(q.lastConsumed).Seconds()
}
diff --git a/examples/derived_gauges/derived_gauge.go b/examples/derived_gauges/derived_gauge.go
index 721742d..07c1301 100644
--- a/examples/derived_gauges/derived_gauge.go
+++ b/examples/derived_gauges/derived_gauge.go
@@ -130,7 +130,7 @@
func (q *queue) Elapsed() float64 {
q.mu.Lock()
defer q.mu.Unlock()
- return time.Now().Sub(q.lastConsumed).Seconds()
+ return time.Since(q.lastConsumed).Seconds()
}
// END tofloat64
diff --git a/internal/internal.go b/internal/internal.go
index 9a63878..81dc718 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -33,5 +33,5 @@
// end as a monotonic time.
// See https://golang.org/pkg/time/#hdr-Monotonic_Clocks
func MonotonicEndTime(start time.Time) time.Time {
- return start.Add(time.Now().Sub(start))
+ return start.Add(time.Since(start))
}
diff --git a/zpages/rpcz.go b/zpages/rpcz.go
index dee28f9..ef4dd15 100644
--- a/zpages/rpcz.go
+++ b/zpages/rpcz.go
@@ -205,7 +205,7 @@
if len(vd.Rows) == 0 {
return
}
- ageSec := float64(time.Now().Sub(programStartTime)) / float64(time.Second)
+ ageSec := float64(time.Since(programStartTime)) / float64(time.Second)
computeRate := func(maxSec, x float64) float64 {
dur := ageSec