where
import Data.Either.Utils ( maybeToEither )
-import Data.Time.Clock ( NominalDiffTime, UTCTime, addUTCTime )
+import Data.Time.Clock ( UTCTime )
import Data.Time.Format ( parseTime )
import System.Locale ( defaultTimeLocale )
import Text.Read ( readMaybe )
time_format :: String
time_format = "%I:%M %p"
--- | The format string for a time_stamp. This omits the leading and
--- trailing space.
+
+-- | The format string for a time_stamp. We keep the leading/trailing
+-- space so that parseTime and formatTime are inverses are one
+-- another, even though there is some confusion as to how these two
+-- functions should behave:
+--
+-- <https://ghc.haskell.org/trac/ghc/ticket/9150>
+--
time_stamp_format :: String
-time_stamp_format = "%B %-d, %Y, at " ++ time_format ++ " ET"
+time_stamp_format = " %B %-d, %Y, at " ++ time_format ++ " ET "
--- | Parse a time stamp from a 'String' (maybe).
---
--- TSN doesn't provide a proper time zone name, so we assume that
--- it's always Eastern Standard Time. EST is UTC-5, so we
--- add five hours to convert to UTC.
+
+-- | Parse a time stamp from a 'String' (maybe). TSN doesn't provide a
+-- proper time zone name, so we parse it as UTC, and maybe our
+-- eventual consumer can figure out a way to deduce the time zone.
--
parse_time_stamp :: String -> Maybe UTCTime
parse_time_stamp =
- fmap add_five . parseTime defaultTimeLocale time_stamp_format
- where
- five_hours :: NominalDiffTime
- five_hours = 5 * 60 * 60
+ parseTime defaultTimeLocale time_stamp_format
- add_five :: UTCTime -> UTCTime
- add_five = addUTCTime five_hours
-- | Extract the \"time_stamp\" element from a document. If we fail