]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/Picklers.hs
Comment out the DTD in Injuries_Detail_XML.xml.
[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 where
7
8 import Data.Time.Clock ( UTCTime )
9 import Data.Time.Format ( formatTime, parseTime )
10 import System.Locale ( defaultTimeLocale )
11 import Text.Read ( readMaybe )
12 import Text.XML.HXT.Arrow.Pickle (
13 XmlPickler(..),
14 xpText,
15 xpWrapMaybe )
16 import Text.XML.HXT.Arrow.Pickle.Xml ( PU )
17
18 instance XmlPickler Bool where
19 xpickle =
20 (to_bool, from_bool) `xpWrapMaybe` xpText
21 where
22 to_bool :: String -> Maybe Bool
23 to_bool = readMaybe
24
25 from_bool :: Bool -> String
26 from_bool = show
27
28
29 -- | (Un)pickle a UTCTime without the time portion.
30 --
31 xp_date :: PU UTCTime
32 xp_date =
33 (to_date, from_date) `xpWrapMaybe` xpText
34 where
35 format = "%-m/%-d/%Y"
36
37 to_date :: String -> Maybe UTCTime
38 to_date = parseTime defaultTimeLocale format
39
40 from_date :: UTCTime -> String
41 from_date = formatTime defaultTimeLocale format