From: Michael Orlitzky Date: Thu, 23 Jan 2014 20:37:53 +0000 (-0500) Subject: Add a new (un)pickler for the auto racing schedule "TBA"-able time field. X-Git-Tag: 0.0.4~18 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=a4dd6d2d508db8dbc28a514cc7a71a3260587f4c;p=dead%2Fhtsn-import.git Add a new (un)pickler for the auto racing schedule "TBA"-able time field. --- diff --git a/src/TSN/Picklers.hs b/src/TSN/Picklers.hs index f80b085..c70b2ba 100644 --- a/src/TSN/Picklers.hs +++ b/src/TSN/Picklers.hs @@ -4,6 +4,7 @@ module TSN.Picklers ( xp_date, xp_gamedate, + xp_tba_time, xp_time, xp_time_stamp ) where @@ -14,6 +15,7 @@ import Data.Time.Format ( formatTime, parseTime ) import System.Locale ( defaultTimeLocale ) import Text.XML.HXT.Arrow.Pickle ( xpText, + xpWrap, xpWrapMaybe ) import Text.XML.HXT.Arrow.Pickle.Xml ( PU ) @@ -100,6 +102,22 @@ xp_time = from_time = formatTime defaultTimeLocale xp_time_format +-- | (Un)pickle a UTCTime without the date portion, allowing for a +-- value of \"TBA\" (which gets translated to 'Nothing'). +-- +xp_tba_time :: PU (Maybe UTCTime) +xp_tba_time = + (to_time, from_time) `xpWrap` xpText + where + to_time :: String -> Maybe UTCTime + to_time s + | s == "TBA" = Nothing + | otherwise = parseTime defaultTimeLocale xp_time_format s + + from_time :: Maybe UTCTime -> String + from_time Nothing = "" + from_time (Just t) = formatTime defaultTimeLocale xp_time_format t + -- | (Un)pickle the \ element format to/from a 'UTCTime'. --