Store realtime times from API response
parent
287ebdcea4
commit
5007ccb287
43
bus.go
43
bus.go
|
@ -6,25 +6,30 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Departure struct {
|
||||
TripID int
|
||||
RealtimeTripId string
|
||||
StopHeadsign string
|
||||
ArrivalTime time.Time
|
||||
DepartureTime time.Time
|
||||
RouteShortName string
|
||||
TripID int
|
||||
RealtimeTripId string
|
||||
StopHeadsign string
|
||||
ArrivalTime time.Time
|
||||
DepartureTime time.Time
|
||||
RealtimeArrivalTime time.Time
|
||||
RealtimeDepartureTime time.Time
|
||||
RouteShortName string
|
||||
}
|
||||
|
||||
type ResponseDeparture struct {
|
||||
TripID int `json:"trip_id"`
|
||||
RealtimeTripId string `json:"realtime_trip_id"`
|
||||
StopHeadsign string `json:"stop_headsign"`
|
||||
ArrivalTime string `json:"arrival_time"`
|
||||
DepartureTime string `json:"departure_time"`
|
||||
Tripdata struct {
|
||||
TripID int `json:"trip_id"`
|
||||
RealtimeTripId string `json:"realtime_trip_id"`
|
||||
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"`
|
||||
} `json:"route"`
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue