1 -- | (Un)picklers for data types present in The Sports Network XML
11 import Data.Time.Clock ( UTCTime )
12 import Data.Time.Format ( formatTime, parseTime )
13 import System.Locale ( defaultTimeLocale )
14 import Text.XML.HXT.Arrow.Pickle (
17 import Text.XML.HXT.Arrow.Pickle.Xml ( PU )
20 -- | (Un)pickle a UTCTime without the time portion.
24 (to_date, from_date) `xpWrapMaybe` xpText
28 to_date :: String -> Maybe UTCTime
29 to_date = parseTime defaultTimeLocale format
31 from_date :: UTCTime -> String
32 from_date = formatTime defaultTimeLocale format
35 -- | (Un)pickle a UTCTime without the date portion.
39 (to_time, from_time) `xpWrapMaybe` xpText
43 to_time :: String -> Maybe UTCTime
44 to_time = parseTime defaultTimeLocale format
46 from_time :: UTCTime -> String
47 from_time = formatTime defaultTimeLocale format
51 -- | Parse a team_id. These are (so far!) three characters long, and
52 -- not necessarily numeric. For simplicity, we return a 'String'
53 -- rather than e.g. a @(Char, Char, Char)@. But unpickling will fail
54 -- if the team_id is longer than three characters.
56 xp_team_id :: PU String
58 (to_team_id, from_team_id) `xpWrapMaybe` xpText
60 to_team_id :: String -> Maybe String
62 | length s <= 3 = Just s
65 from_team_id :: String -> String