all repos — flounder @ 609d53702630916ee1b04f69e19fb67ca820bdbc

A small site builder for the Gemini protocol

Fix timeago function
alex wennerberg alex@alexwennerberg.com
Mon, 09 Nov 2020 17:14:04 -0800
commit

609d53702630916ee1b04f69e19fb67ca820bdbc

parent

3341469aa1b6cea92fc842b606343e1d8d996687

1 files changed, 20 insertions(+), 4 deletions(-)

jump to
M utils.goutils.go

@@ -14,13 +14,29 @@

func timeago(t *time.Time) string { d := time.Since(*t) if d.Seconds() < 60 { - return fmt.Sprintf("%d seconds ago", int(d.Seconds())) + seconds := int(d.Seconds()) + if seconds == 1 { + return "1 second ago" + } + return fmt.Sprintf("%d seconds ago", seconds) } else if d.Minutes() < 60 { - return fmt.Sprintf("%d minutes ago", int(d.Minutes())) + minutes := int(d.Minutes()) + if minutes == 1 { + return "1 minute ago" + } + return fmt.Sprintf("%d minutes ago", minutes) } else if d.Hours() < 24 { - return fmt.Sprintf("%d hours ago", int(d.Hours())) + hours := int(d.Hours()) + if hours == 1 { + return "1 hour ago" + } + return fmt.Sprintf("%d hours ago", hours) } else { - return fmt.Sprintf("%d days ago", int(d.Hours())/24) + days := int(d.Hours()) / 24 + if days == 1 { + return "1 day ago" + } + return fmt.Sprintf("%d days ago", days) } }