aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2022-03-30 16:58:31 +0000
committerr <r@freesoftwareextremist.com>2022-03-30 17:02:46 +0000
commit2a014716216d445953b4832958e80c739bb02c2c (patch)
tree13ae5ebbdfb1f9e0fe83e2590062f2d53225bace
parent2d49ff9fb4ea9b0e88df1621e954246bc1851de6 (diff)
downloadbloat-2a014716216d445953b4832958e80c739bb02c2c.tar.gz
bloat-2a014716216d445953b4832958e80c739bb02c2c.zip
Fix duration overflow
time.Sub() returns int64 duration in nanoseconds, which can only represent around 290 years.
-rw-r--r--renderer/renderer.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/renderer/renderer.go b/renderer/renderer.go
index 6e50270..f1595a5 100644
--- a/renderer/renderer.go
+++ b/renderer/renderer.go
@@ -73,16 +73,15 @@ func displayInteractionCount(c int64) string {
return ""
}
-func DurToStr(dur time.Duration) string {
- s := dur.Seconds()
+func durToStr(s int64) string {
if s < 60 {
return strconv.Itoa(int(s)) + "s"
}
- m := dur.Minutes()
+ m := s / 60
if m < 60*2 {
return strconv.Itoa(int(m)) + "m"
}
- h := dur.Hours()
+ h := m / 60
if h < 24*2 {
return strconv.Itoa(int(h)) + "h"
}
@@ -94,24 +93,24 @@ func DurToStr(dur time.Duration) string {
if mo < 12*2 {
return strconv.Itoa(int(mo)) + "mo"
}
- y := mo / 12
+ y := d / 365
return strconv.Itoa(int(y)) + "y"
}
func timeSince(t time.Time) string {
- d := time.Since(t)
+ d := time.Now().Unix() - t.Unix()
if d < 0 {
d = 0
}
- return DurToStr(d)
+ return durToStr(d)
}
func timeUntil(t time.Time) string {
- d := time.Until(t)
+ d := t.Unix() - time.Now().Unix()
if d < 0 {
d = 0
}
- return DurToStr(d)
+ return durToStr(d)
}
func formatTimeRFC3339(t time.Time) string {