split output code into method

This commit is contained in:
Nick Griffey 2024-02-22 22:33:54 -06:00
parent 1ecf16bd0a
commit 76a56879b0
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)
}