print "years ago" instead of date when not yearknown
This commit is contained in:
parent
76a56879b0
commit
2925fb174c
17
main.go
17
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() {
|
||||
|
|
Loading…
Reference in New Issue