import Control.Applicative( (<$>), (<*>), liftA, liftA2 ) import Data.DateTime( parseDateTime, startOfTime, diffSeconds, formatDateTime ) import Data.List( zip4, zipWith4, transpose ) import Data.List.Split( splitOn ) import Data.Maybe( fromJust, fromMaybe ) import Data.Monoid( mempty ) import Data.Time.Clock( secondsToDiffTime ) import Options.Applicative( execParser, info, strOption, long ) import System.Environment( getArgs ) import HMSTime( HMSTime(..), secondsToHMS ) import Diddo.Entry( DiddoEntry(..) ) data DiddoOpts = DiddoOpts { inDateFmt :: String , inFile :: String } mainWithOpts :: DiddoOpts -> IO () mainWithOpts opts = do [timestrings_finish , entries ] <- transpose . map (splitOn ";") . lines <$> readFile (inFile opts) let utcTimes_finish = map (fromMaybe (error "Input data broken.") . parseDateTime (inDateFmt opts)) timestrings_finish entry_deltas_HMMSS = zipWith (\x y -> secondsToHMS $ diffSeconds x y) utcTimes_finish (startOfTime : init utcTimes_finish) diddos_summarized = zipWith4 DiddoEntry ("" : init timestrings_finish) timestrings_finish entry_deltas_HMMSS entries mapM_ print diddos_summarized main :: IO () main = execParser opts >>= mainWithOpts where opts = info parser mempty parser = DiddoOpts <$> strOption ( long "indateform" ) <*> strOption ( long "infile" )