print "years ago" instead of date when not yearknown

This commit is contained in:
filifa 2024-03-19 20:31:32 -05:00
parent 227c6661ac
commit c82b2bf6df
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() {