From e84f2967a3252f474d9618fb19df6f571c3bc762 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 3 Dec 2022 14:27:49 +0100 Subject: unreasonably stupid and probably unnecessary code (but maybe google will like it) --- lib/Server/GTFS_RT.hs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/Server/GTFS_RT.hs') diff --git a/lib/Server/GTFS_RT.hs b/lib/Server/GTFS_RT.hs index 20e6fa7..9da9be9 100644 --- a/lib/Server/GTFS_RT.hs +++ b/lib/Server/GTFS_RT.hs @@ -28,7 +28,8 @@ import Data.Text.Encoding (e import Data.Time.Calendar (Day, toGregorian) import Data.Time.Clock (UTCTime (utctDay), - getCurrentTime) + getCurrentTime, + addUTCTime) import Data.Time.Clock.POSIX (getPOSIXTime) import Data.Time.Clock.System (SystemTime (systemSeconds), getSystemTime, @@ -46,7 +47,7 @@ import GTFS (G Seconds (..), Stop (..), Trip (..), - stationId, + stationId, toUTC, TripID, tripsOnDay) import GTFS.Realtime.Alert as AL (Alert (..)) @@ -110,7 +111,7 @@ toStupidDate date = toUtf8 where ndigits = length (show num) -- | basically unix timestamps, raw (because why not i guess) -toStupidTime :: UTCTime -> Word64 +toStupidTime :: Num i => UTCTime -> i toStupidTime = fromIntegral . systemSeconds . utcToSystemTime gtfsRealtimeServer :: GTFS -> Pool SqlBackend -> Service GtfsRealtimeAPI @@ -171,9 +172,15 @@ gtfsRealtimeServer gtfs@GTFS{..} dbpool = handleServiceAlerts :<|> handleTripUpd { STU.stop_sequence = Just (fromIntegral stopSequence) , STU.stop_id = Just (toUtf8 $ stationId stopStation) , STU.arrival = Just ( - defaultValue { STE.delay = Just $ fromIntegral $ unSeconds $ trainAnchorDelay, STE.uncertainty = Just 60 }) + defaultValue + { STE.delay = Just $ fromIntegral $ unSeconds $ trainAnchorDelay + , STE.time = Just $ (toStupidTime (addUTCTime (fromIntegral $ unSeconds trainAnchorDelay) (toUTC stopArrival tzseries today))) + , STE.uncertainty = Just 60 }) , STU.departure = Just ( - defaultValue { STE.delay = Just $ fromIntegral $ unSeconds $ trainAnchorDelay, STE.uncertainty = Just 60 }) + defaultValue + { STE.delay = Just $ fromIntegral $ unSeconds $ trainAnchorDelay + , STE.time = Just $ (toStupidTime (addUTCTime (fromIntegral $ unSeconds trainAnchorDelay) (toUTC stopDeparture tzseries today))) + , STE.uncertainty = Just 60 }) , STU.departure_occupancy_status = Nothing , STU.schedule_relationship = Just SR.SCHEDULED , STU.stop_time_properties = Nothing -- cgit v1.2.3