1 -- | (Un)picklers for data types present in The Sports Network XML
10 import Data.Time.Clock ( UTCTime )
11 import Data.Time.Format ( formatTime, parseTime )
12 import System.Locale ( defaultTimeLocale )
13 import Text.XML.HXT.Arrow.Pickle (
16 import Text.XML.HXT.Arrow.Pickle.Xml ( PU )
19 -- | (Un)pickle a UTCTime without the time portion.
23 (to_date, from_date) `xpWrapMaybe` xpText
27 to_date :: String -> Maybe UTCTime
28 to_date = parseTime defaultTimeLocale format
30 from_date :: UTCTime -> String
31 from_date = formatTime defaultTimeLocale format
34 -- | Parse a team_id. These are (so far!) three characters long, and
35 -- not necessarily numeric. For simplicity, we return a 'String'
36 -- rather than e.g. a @(Char, Char, Char)@. But unpickling will fail
37 -- if the team_id is longer than three characters.
39 xp_team_id :: PU String
41 (to_team_id, from_team_id) `xpWrapMaybe` xpText
43 to_team_id :: String -> Maybe String
45 | length s <= 3 = Just s
48 from_team_id :: String -> String