64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package types
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type StopTime struct {
|
|
departureTime int
|
|
Stop *Stop `json:"stop"`
|
|
TripID string `json:"trip_id" csv:"trip_id"`
|
|
ArrivalTime string `json:"arrival_time" csv:"arrival_time"`
|
|
DepartureTime string `json:"departure_time" csv:"departure_time"`
|
|
StopID string `json:"stop_id" csv:"stop_id"`
|
|
StopSequence int `json:"stop_sequence" csv:"stop_sequence"`
|
|
PickupType int `json:"pickup_type" csv:"pickup_type"`
|
|
DropOffType int `json:"drop_off_type" csv:"drop_off_type"`
|
|
}
|
|
|
|
func parseTime(s string) int {
|
|
parts := strings.Split(s, ":")
|
|
if len(parts) != 3 {
|
|
return 0
|
|
}
|
|
h, _ := strconv.Atoi(parts[0])
|
|
m, _ := strconv.Atoi(parts[1])
|
|
sec, _ := strconv.Atoi(parts[2])
|
|
return h*3600 + m*60 + sec
|
|
}
|
|
|
|
func (st *StopTime) DepartTimeAsSeconds() int {
|
|
if st.departureTime > 0 {
|
|
return st.departureTime
|
|
}
|
|
if st.DepartureTime == "" {
|
|
return 0
|
|
}
|
|
|
|
st.departureTime = parseTime(st.DepartureTime)
|
|
return st.departureTime
|
|
}
|
|
|
|
func (st *StopTime) DepartsAfter(when time.Time) bool {
|
|
secondsAfterMidnight := st.DepartTimeAsSeconds()
|
|
return secondsAfterMidnight >= when.Hour()*3600+when.Minute()*60+when.Second()
|
|
}
|
|
|
|
// func (st *StopTime) GetPossibleTrips() iter.Seq[*Trip] {
|
|
// return func(yield func(*Trip) bool) {
|
|
// for _, trip := range st.Stop.trips {
|
|
// if trip.TripID != st.TripID {
|
|
// if !yield(trip) {
|
|
// return
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
func (st *StopTime) SetStop(stop *Stop) {
|
|
st.Stop = stop
|
|
}
|