Skip to content

Commit

Permalink
added back proper duration rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaya-Sem committed Aug 19, 2024
1 parent 3a44e15 commit b36f402
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions cmd/api/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ func ParseConnections(body []byte) ([]Connection, error) {
return result.Connection, nil
}

func GetDurationInMinutes(c Connection) string {
duration, err := strconv.Atoi(c.Duration)
if err != nil {
fmt.Printf("Duration could not be parsed: %s", duration)
}

duration /= 60

return strconv.Itoa(duration) + "m"
}

func (c Connection) GetDelayInSeconds() int {
delay, err := strconv.Atoi(c.Departure.Delay)

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func handleConnection(stationFrom string, stationTo string) {

columns := []teaTable.Column{
{Title: "Departure", Width: 7},
{Title: "", Width: 2},
{Title: "", Width: 4},
{Title: "Duration", Width: 7},
{Title: "Arrival", Width: 7},
{Title: "Track", Width: 10},
Expand All @@ -61,7 +61,7 @@ func handleConnection(stationFrom string, stationTo string) {
rows[i] = teaTable.Row{
cmd.UnixToHHMM(conn.Departure.Time),
delay,
conn.Duration,
api.GetDurationInMinutes(conn),
cmd.UnixToHHMM(conn.Arrival.Time),
conn.Departure.Platform,
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func handleTimetable(stationName string) {

columns := []teaTable.Column{
{Title: "", Width: 5},
{Title: "", Width: 4},
{Title: "", Width: 5},
{Title: "Destination", Width: 20},
{Title: "Track", Width: 10},
}
Expand Down

0 comments on commit b36f402

Please sign in to comment.