+ from_time t =
+ replace "AM" "A.M." (replace "PM" "P.M." s)
+ where
+ s = formatTime defaultTimeLocale nopad_time_format t
+
+
+-- | (Un)pickle a UTCTime without the date portion, allowing for a
+-- value of \"TBA\" (which gets translated to 'Nothing').
+--
+-- /Examples/:
+--
+-- A failed parse will return 'Nothing':
+--
+-- >>> let tn = text_node "YO"
+-- >>> unpickleDoc xp_tba_time tn
+-- Just Nothing
+--
+-- And so will parsing a \"TBA\":
+--
+-- >>> let tn = text_node "TBA"
+-- >>> unpickleDoc xp_tba_time tn
+-- Just Nothing
+--
+-- But re-pickling 'Nothing' gives only \"TBA\":
+--
+-- >>> pickleDoc xp_tba_time Nothing
+-- NTree (XTag "/" []) [NTree (XText "TBA") []]
+--
+-- A normal time is also parsed successfully, of course:
+--
+-- >>> let tn = text_node "08:10 PM"
+-- >>> unpickleDoc xp_tba_time tn
+-- Just (Just 1970-01-01 20:10:00 UTC)
+--
+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 time_format s
+
+ from_time :: Maybe UTCTime -> String
+ from_time Nothing = "TBA"
+ from_time (Just t) = formatTime defaultTimeLocale time_format t
+
+
+
+-- | (Un)pickle the \<time_stamp\> element format to/from a 'UTCTime'.
+-- The time_stamp elements look something like,
+--
+-- \<time_stamp\> January 6, 2014, at 10:11 PM ET \</time_stamp\>
+--
+-- TSN doesn't provide a proper time zone name, so we assume that
+-- it's always Eastern Standard Time. EST is UTC-5, so we
+-- add/subtract 5 hours to convert to/from UTC.
+--
+-- Examples:
+--
+-- >>> let tn = text_node " January 6, 2014, at 10:11 PM ET "
+-- >>> unpickleDoc xp_time_stamp tn
+-- Just 2014-01-07 03:11:00 UTC
+--
+xp_time_stamp :: PU UTCTime
+xp_time_stamp =
+ (parse_time_stamp, from_time_stamp) `xpWrapMaybe` xpText
+ where
+ five_hours :: NominalDiffTime
+ five_hours = 5 * 60 * 60
+
+ subtract_five :: UTCTime -> UTCTime
+ subtract_five = addUTCTime (-1 * five_hours)