print "years ago" instead of date when not yearknown

This commit is contained in:
Nick Griffey 2024-02-22 22:54:45 -06:00
parent 76a56879b0
commit 2925fb174c
1 changed files with 15 additions and 2 deletions

17
main.go
View File

@ -7,6 +7,7 @@ import (
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"log" "log"
"math" "math"
"strconv"
"time" "time"
) )
@ -63,9 +64,21 @@ func (event *EventsRow) Output() (int64, string, string) {
log.Fatal(err) 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() { func main() {