From a4dd6d2d508db8dbc28a514cc7a71a3260587f4c Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 23 Jan 2014 15:37:53 -0500 Subject: [PATCH] Add a new (un)pickler for the auto racing schedule "TBA"-able time field. --- src/TSN/Picklers.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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'. -- -- 2.43.2