split output code into method

This commit is contained in:
filifa 2024-03-19 20:31:32 -05:00
parent a2f48ed7cc
commit 227c6661ac
1 changed files with 17 additions and 11 deletions

28
main.go
View File

@ -52,6 +52,22 @@ func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
return event, err
}
func (event *EventsRow) Output() (int64, string, string) {
timestamp, err := event.timestamp.Value()
if err != nil {
log.Fatal(err)
}
desc, err := event.description.Value()
if err != nil {
log.Fatal(err)
}
date := time.Unix(timestamp.(int64), 0)
return timestamp.(int64), date.String(), desc.(string)
}
func main() {
percent := flag.Float64("p", -1, "percentage")
flag.Parse()
@ -75,16 +91,6 @@ func main() {
log.Fatal(err)
}
timestamp, err := event.timestamp.Value()
if err != nil {
log.Fatal(err)
}
desc, err := event.description.Value()
if err != nil {
log.Fatal(err)
}
date := time.Unix(timestamp.(int64), 0)
timestamp, date, desc := event.Output()
fmt.Printf("%v\t%v\t%v\n", timestamp, date, desc)
}