]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/TSN/Picklers.hs
Add SportInfo support for mlbrunsleadersxml.dtd.
[dead/htsn-import.git] / src / TSN / Picklers.hs
index ff7b0d1e677e9cff2c9cd469c77e226be272a2a6..ea335c81f2894e8de38a44bddea3c5b2938f82c4 100644 (file)
@@ -35,8 +35,9 @@ import TSN.Parse (
 -- | The format string for a base date in m/d/yyyy format. The
 --   day/month are not padded at all. This will match for example,
 --
---   * 2/15/1983
---   * 1/1/0000
+--   * 2\/15\/1983
+--
+--   * 1\/1\/0000
 --
 date_format :: String
 date_format = "%-m/%-d/%Y"
@@ -46,8 +47,9 @@ date_format = "%-m/%-d/%Y"
 --   day/month are padded to two characters with zeros. This will
 --   match for example,
 --
---   * 02/15/1983
---   * 01/01/0000
+--   * 02\/15\/1983
+--
+--   * 01\/01\/0000
 --
 date_format_padded :: String
 date_format_padded = "%0m/%0d/%Y"
@@ -108,9 +110,11 @@ format_commas x =
 -- | Parse \<Earnings\> from an 'AutoRaceResultsListing'. These are
 --   essentially 'Int's, but they look like,
 --
---   * <Earnings>336,826</Earnings>
---   * <Earnings>1,000,191</Earnings>
---   * <Earnings>TBA</Earnings>
+--   * \<Earnings\>336,826\</Earnings\>
+--
+--   * \<Earnings\>1,000,191\</Earnings\>
+--
+--   * \<Earnings\>TBA\</Earnings\>
 --
 xp_earnings :: PU (Maybe Int)
 xp_earnings =
@@ -122,7 +126,7 @@ xp_earnings =
     to_earnings :: String -> Maybe Int
     to_earnings s
       | s == "TBA" = Nothing
-      | otherwise = (read . strip_commas . show) s
+      | otherwise = Just  $ (read . strip_commas) s
 
     from_earnings :: Maybe Int -> String
     from_earnings Nothing = "TBA"
@@ -132,10 +136,11 @@ xp_earnings =
 -- | (Un)pickle a 'UTCTime' from a \<RaceDate\> element in an
 --   'AutoRaceResults' message.
 --
---   Example:
+--   Examples:
+--
+--   * \<RaceDate\>6/1/2014 1:00:00 PM\</RaceDate\>
 --
---   <RaceDate>6/1/2014 1:00:00 PM</RaceDate>
---   <RaceDate>5/24/2014 2:45:00 PM</RaceDate>
+--   * \<RaceDate\>5/24/2014 2:45:00 PM\</RaceDate\>
 --
 xp_racedate :: PU UTCTime
 xp_racedate =
@@ -227,7 +232,7 @@ xp_tba_time =
       | otherwise = parseTime defaultTimeLocale time_format s
 
     from_time :: Maybe UTCTime -> String
-    from_time Nothing = ""
+    from_time Nothing = "TBA"
     from_time (Just t) = formatTime defaultTimeLocale time_format t