]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/Picklers.hs
Don't bother with the three-character limit on team_id fields; Postgres doesn't care.
[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_time )
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 -- | (Un)pickle a UTCTime without the date portion.
35 --
36 xp_time :: PU UTCTime
37 xp_time =
38 (to_time, from_time) `xpWrapMaybe` xpText
39 where
40 format = "%I:%M %p"
41
42 to_time :: String -> Maybe UTCTime
43 to_time = parseTime defaultTimeLocale format
44
45 from_time :: UTCTime -> String
46 from_time = formatTime defaultTimeLocale format
47