module TSN.Picklers (
xp_date,
xp_gamedate,
+ xp_tba_time,
xp_time,
xp_time_stamp )
where
import System.Locale ( defaultTimeLocale )
import Text.XML.HXT.Arrow.Pickle (
xpText,
+ xpWrap,
xpWrapMaybe )
import Text.XML.HXT.Arrow.Pickle.Xml ( PU )
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 \<time_stamp\> element format to/from a 'UTCTime'.
--