From 2925fb174c5ac2bca6bd902b9b75a25be09ec12a Mon Sep 17 00:00:00 2001 From: Nick Griffey Date: Thu, 22 Feb 2024 22:54:45 -0600 Subject: [PATCH] print "years ago" instead of date when not yearknown --- main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 0c1bede..e2aecd7 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( _ "github.com/mattn/go-sqlite3" "log" "math" + "strconv" "time" ) @@ -63,9 +64,21 @@ func (event *EventsRow) Output() (int64, string, string) { log.Fatal(err) } - date := time.Unix(timestamp.(int64), 0) + yearknown, err := event.yearknown.Value() + if err != nil { + log.Fatal(err) + } - return timestamp.(int64), date.String(), desc.(string) + var ago string + date := time.Unix(timestamp.(int64), 0) + if yearknown == nil || !yearknown.(bool) { + yeardiff := time.Now().Year() - date.Year() + ago = strconv.Itoa(yeardiff) + " years ago" + } else { + ago = date.String() + } + + return timestamp.(int64), ago, desc.(string) } func main() {