@@ -15,6 +15,7 @@ import Data.Maybe (listToMaybe)
1515import System.Environment (getArgs)
1616import System.Exit (exitWith, exitSuccess, ExitCode(ExitFailure))
1717import System.Locale (defaultTimeLocale)
18+import Control.Monad (guard)
1819
1920version :: IO a
2021version = do
@@ -33,7 +34,8 @@ illegalOpt opt = do
3334 putStrLn $ "hzdump: illegal option -- " ++ [opt]
3435 usage
3536
36−data Option = Version | Illegal Char | Verbose (Maybe Integer) | Now
37+data Option = Version | Illegal Char |
38+ Verbose (Maybe Integer, Maybe Integer) | Now
3739 deriving (Eq, Ord, Show)
3840
3941main = do
@@ -41,7 +43,7 @@ main = do
4143 (getTimes, displayTime) <- case opts of
4244 Version -> version
4345 Illegal opt -> illegalOpt opt
44− Verbose yr -> return (transitionTimesUntil yr, displayVerbose)
46+ Verbose rng -> return (transitionTimes rng, displayVerbose)
4547 _ -> do now <- getCurrentTime
4648 return (const [now], displayConcise)
4749 tzss <- mapM getZone zones
@@ -56,17 +58,26 @@ main = do
5658
5759parseArgs :: [String] -> (Option, [FilePath])
5860parseArgs args | "--version" `elem` args = (Version, [])
59−parseArgs args = getOpts False Nothing args
61+parseArgs args = getOpts False (Nothing, Nothing) args
6062 where
6163 getOpts _ cutoff ("-v":args) = getOpts True cutoff args
62− getOpts v Nothing ("-c":c:args) = maybe (Illegal 'c', [])
63− (\y -> getOpts v (Just y) args) $
64− maybeRead c
64+ getOpts v _ ("-c":c:args) = maybe (Illegal 'c', [])
65+ (\y -> getOpts v y args) $
66+ parseCutoff c
6567 getOpts v cutoff ("--":zones ) = (opts v cutoff, zones)
6668 getOpts _ _ (('-':x:_):_) = (Illegal x, [])
6769 getOpts v cutoff zones = (opts v cutoff, zones)
70+
6871 opts v cutoff = if v then Verbose cutoff else Now
6972
73+ parseCutoff c = let p0 = listToMaybe $ reads c
74+ los = fmap fst p0
75+ his = do str <- fmap snd p0
76+ let (comma, str1) = splitAt 1 str
77+ guard $ comma == ","
78+ maybeRead str1
79+ in los >> Just (maybe (Nothing, los) ((,) los . Just) his)
80+
7081displayConcise :: TimeZoneSeries -> UTCTime -> String
7182displayConcise tzs t = formatTime defaultTimeLocale format $
7283 ZoneSeriesTime t tzs
@@ -79,9 +90,11 @@ displayVerbose tzs t = concat [displayConcise utcTZ t, " = ",
7990 where
8091 isdst = timeZoneSummerOnly $ timeZoneFromSeries tzs t
8192
82−transitionTimesUntil :: Maybe Integer -> TimeZoneSeries -> [UTCTime]
83−transitionTimesUntil yr =
84− maybe id (dropWhile . (>=)) (fmap happyNewYear yr) .
93+transitionTimes :: (Maybe Integer, Maybe Integer) -> TimeZoneSeries ->
94+ [UTCTime]
95+transitionTimes (lo, hi) =
96+ maybe id (takeWhile . (>)) (fmap happyNewYear hi) .
97+ maybe id (dropWhile . (>)) (fmap happyNewYear lo) .
8598 addBugs . addPrevSecond . actualTransitions
8699 where
87100 happyNewYear y = UTCTime (fromGregorian y 1 1) 0