]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/Picklers.hs
Remove unused imports.
[dead/htsn-import.git] / src / TSN / Picklers.hs
1 -- | (Un)picklers for data types present in The Sports Network XML
2 -- feed.
3 --
4 module TSN.Picklers (
5 xp_date,
6 xp_team_id )
7 where
8
9 -- System imports.
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 (
14 xpText,
15 xpWrapMaybe )
16 import Text.XML.HXT.Arrow.Pickle.Xml ( PU )
17
18
19 -- | (Un)pickle a UTCTime without the time portion.
20 --
21 xp_date :: PU UTCTime
22 xp_date =
23 (to_date, from_date) `xpWrapMaybe` xpText
24 where
25 format = "%-m/%-d/%Y"
26
27 to_date :: String -> Maybe UTCTime
28 to_date = parseTime defaultTimeLocale format
29
30 from_date :: UTCTime -> String
31 from_date = formatTime defaultTimeLocale format
32
33
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.
38 --
39 xp_team_id :: PU String
40 xp_team_id =
41 (to_team_id, from_team_id) `xpWrapMaybe` xpText
42 where
43 to_team_id :: String -> Maybe String
44 to_team_id s
45 | length s <= 3 = Just s
46 | otherwise = Nothing
47
48 from_team_id :: String -> String
49 from_team_id = id