File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package cmd
33import (
44 "fmt"
55 "os"
6+ "strings"
67 "time"
78
89 "github.com/spf13/cobra"
@@ -44,3 +45,7 @@ func unixMillisToTime(millis uint64) time.Time {
4445 seconds := int64 (millis / 1000 )
4546 return time .Unix (seconds , 0 )
4647}
48+
49+ func formatTimeDelta (d time.Duration ) string {
50+ return strings .Split (d .String (), "." )[0 ]
51+ }
Original file line number Diff line number Diff line change @@ -40,7 +40,10 @@ var stopsCmd = &cobra.Command{
4040 if remainingDuration < 0 {
4141 return "-"
4242 }
43- return remainingDuration .String ()
43+ if remainingDuration < time .Duration (time .Minute * 3 ) {
44+ return "GET OUT NOW"
45+ }
46+ return formatTimeDelta (remainingDuration )
4447 }()
4548 stopView .DelayReasons = func () string {
4649 reasons := []string {}
Original file line number Diff line number Diff line change 77 "io"
88 "net/http"
99 "os"
10+ "time"
1011
1112 "github.com/spf13/cobra"
1213
@@ -33,14 +34,15 @@ type Trip struct {
3334 NextStop string `header:"Next Stop"`
3435 StopsToDestination int
3536 Progress string `header:"Progress"`
37+ TimeToArrival string `header:"Arriving"`
3638}
3739
3840type StopInfo struct {
3941 ScheduledNext string `json:"scheduledNext"`
4042 ActualNext string `json:"actualNext"`
4143 ActualLast string `json:"actualLast"`
4244 ActualLastStarted string `json:"actualLastStarted"`
43- FinalStationName string `header:"FD" json:"finalStationName"`
45+ FinalStationName string `json:"finalStationName"`
4446}
4547
4648type Stop struct {
@@ -199,6 +201,21 @@ func refreshTrip() (Trip, error) {
199201 }
200202 return fmt .Sprintf ("%d/%d" , departedStops , envelope .Trip .StopsToDestination )
201203 }()
204+ envelope .Trip .TimeToArrival = func () string {
205+ var arrival uint64
206+ for _ , stop := range envelope .Trip .Stops {
207+ if stop .Station .Name == envelope .Trip .YourDestination {
208+ arrival = stop .TimeTable .ActualArrivalTime
209+ break
210+ }
211+ }
212+ arrivalTime := unixMillisToTime (arrival )
213+ remainingDuration := time .Until (arrivalTime )
214+ if remainingDuration < time .Duration (time .Minute * 3 ) {
215+ return "GET OUT NOW"
216+ }
217+ return formatTimeDelta (remainingDuration )
218+ }()
202219
203220 return envelope .Trip , nil
204221}
You can’t perform that action at this time.
0 commit comments