where
-- System imports.
+import Data.List ( intercalate )
+import Data.List.Split ( chunksOf )
import Data.String.Utils ( replace )
import Data.Time.Clock ( NominalDiffTime, UTCTime, addUTCTime )
import Data.Time.Format ( formatTime, parseTime )
from_date = formatTime defaultTimeLocale date_format_padded
+
+-- | Format a number as a string using a comma as the thousands
+-- separator.
+--
+-- Examples:
+--
+-- >>> format_commas 0
+-- "0"
+-- >>> format_commas 10
+-- "10"
+-- >>> format_commas 100
+-- "100"
+-- >>> format_commas 1000
+-- "1,000"
+-- >>> format_commas 10000
+-- "10,000"
+-- >>> format_commas 100000
+-- "100,000"
+-- >>> format_commas 1000000
+-- "1,000,000"
+--
+format_commas :: Int -> String
+format_commas x =
+ reverse (intercalate "," $ chunksOf 3 $ reverse $ show x)
+
-- | Parse \<Earnings\> from an 'AutoRaceResultsListing'. These are
-- essentially 'Int's, but they look like,
--
| otherwise = (read . strip_commas . show) s
from_earnings :: Maybe Int -> String
- from_earnings Nothing = ""
- from_earnings (Just i) = show i
+ from_earnings Nothing = "TBA"
+ from_earnings (Just i) = format_commas i
-- | (Un)pickle a 'UTCTime' from a \<RaceDate\> element in an
-- | There's some kind of goddamned bug causing the doctests to commit
-- suicide when run on src/Main.hs. Since we only have doctests in
--- TSN.Codegen for now, just test that.
+-- TSN.Codegen and TSN.Picklers for now, just test those.
--
main :: IO ()
main = doctest [ "-isrc",
"-idist/build/autogen",
- "src/TSN/Codegen.hs" ]
+ "src/TSN/Codegen.hs",
+ "src/TSN/Picklers.hs"]