flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 1d9df31cb10bb27d2153770b3c0c2b53aba725dd
parent 6d376afc164fd144e7976f0e44ce8dfb4f64a5dd
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 27 Oct 2021 11:57:24 -0700

Refactor timeago

Diffstat:
Mutils.go | 35+++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/utils.go b/utils.go @@ -101,30 +101,25 @@ func isGemini(filename string) bool { func timeago(t *time.Time) string { d := time.Since(*t) + var metric string + var amount int if d.Seconds() < 60 { - seconds := int(d.Seconds()) - if seconds == 1 { - return "1 second ago" - } - return fmt.Sprintf("%d seconds ago", seconds) + amount = int(d.Seconds()) + metric = "second" } else if d.Minutes() < 60 { - minutes := int(d.Minutes()) - if minutes == 1 { - return "1 minute ago" - } - return fmt.Sprintf("%d minutes ago", minutes) + amount = int(d.Minutes()) + metric = "minute" } else if d.Hours() < 24 { - hours := int(d.Hours()) - if hours == 1 { - return "1 hour ago" - } - return fmt.Sprintf("%d hours ago", hours) + amount = int(d.Hours()) + metric = "hour" } else { - days := int(d.Hours()) / 24 - if days == 1 { - return "1 day ago" - } - return fmt.Sprintf("%d days ago", days) + amount = int(d.Hours()) / 24 + metric = "day" + } + if amount == 1 { + return fmt.Sprintf("%d %s ago", amount, metric) + } else { + return fmt.Sprintf("%d %ss ago", amount, metric) } } func GetIPFromRemoteAddress(remoteAddress string) string {