From f939da1301dd537330b5a66d157fe38b8c2ea8b3 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 9 Mar 2023 21:14:54 +0100 Subject: vdv 452: apply some corrections --- vdv-server/VDV451.hs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'vdv-server/VDV451.hs') diff --git a/vdv-server/VDV451.hs b/vdv-server/VDV451.hs index 8e8a841..c1d0842 100644 --- a/vdv-server/VDV451.hs +++ b/vdv-server/VDV451.hs @@ -28,6 +28,7 @@ import Data.Time.Format.ISO8601 (formatShow) import Data.Data (Proxy (..)) import Data.Time.Calendar.MonthDay (monthAndDayToDayOfYear) import Codec.Archive.Zip (toEntry, emptyArchive, addEntryToArchive, Archive) +import Debug.Trace (trace) class ÖPNVEncode a where encode :: a -> ByteString @@ -47,19 +48,20 @@ instance ÖPNVEncode Text where a -> [a] instance ÖPNVEncode Day where - encode day = "\""+|crop 2 d|+"."+|crop 2 m|+"."+|crop 4 y|+"\"" + encode day = encode $ (fromInteger y*10000) + m*100 + d where (y,m,d) = toGregorian day + -- | for things which can be encoded as either string or number, --- this module defaults to strings. Add this newtype to the schema --- to make things encode as numbers instead. -newtype AsNumber a = AsNumber a +-- this module defaults to numbers. Add this newtype to the schema +-- to make things encode as strings instead. +newtype AsText a = AsText a -instance ÖPNVEncode (AsNumber Day) where - encode (AsNumber day) = - encode (d*1000000 + m*10000 + (fromInteger y `mod` 10000)) +instance ÖPNVEncode (AsText Day) where + encode (AsText day) = "\""+|crop 2 d|+"."+|crop 2 m|+"."+|crop 4 y|+"\"" where (y,m,d) = toGregorian day + instance ÖPNVEncode DiffTime where encode = C8.pack . formatTime defaultTimeLocale "\"%2H:%2M:%2S\"" @@ -148,7 +150,7 @@ data ÖPNVOptions = ÖPNVOptions öpnvSchnittstellenDaten :: forall a. ÖPNVDatum a => ÖPNVOptions -> UTCTime -> Vector a -> LB.ByteString öpnvSchnittstellenDaten ÖPNVOptions{..} time rows = LB.intercalate "\n" $ fmap mkRow [ [F MOD, Raw "DD.MM.YYYY", Raw "HH:MM:SS", Raw "free"] - , [F SRC, F öpnvSource, F (utctDay time), F (utctDayTime time) ] + , [F SRC, F öpnvSource, (F . AsText . utctDay) time, F (utctDayTime time) ] , [F CHS, F ("ISO8859-1" :: Text)] , [F VER, F öpnvProgramVersion] , [F IFV, F ("1.0" :: Text)] -- cgit v1.2.3