Store realtime times from API response

main
Jasper Bok 2024-04-15 19:43:32 +02:00
parent 287ebdcea4
commit 5007ccb287
1 changed files with 31 additions and 12 deletions

19
bus.go
View File

@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/url"
"strconv"
"time"
)
@ -15,6 +16,8 @@ type Departure struct {
StopHeadsign string
ArrivalTime time.Time
DepartureTime time.Time
RealtimeArrivalTime time.Time
RealtimeDepartureTime time.Time
RouteShortName string
}
@ -24,6 +27,8 @@ type ResponseDeparture struct {
StopHeadsign string `json:"stop_headsign"`
ArrivalTime string `json:"arrival_time"`
DepartureTime string `json:"departure_time"`
RealtimeArrivalTime int `json:"realtime_arrival_time"`
RealtimeDepartureTime int `json:"realtime_departure_time"`
Tripdata struct {
Route struct {
RouteShortName string `json:"route_short_name"`
@ -52,6 +57,20 @@ func (rd ResponseDeparture) ToDeparture() (Departure, error) {
}
departure.DepartureTime = _time
if rd.RealtimeArrivalTime != 0 {
_time, err = parseUnixTimestamp(strconv.Itoa(rd.RealtimeArrivalTime))
if err == nil {
departure.RealtimeArrivalTime = _time
}
}
if rd.RealtimeDepartureTime != 0 {
_time, err = parseUnixTimestamp(strconv.Itoa(rd.RealtimeDepartureTime))
if err == nil {
departure.RealtimeDepartureTime = _time
}
}
return departure, nil
}