summaryrefslogtreecommitdiff
path: root/diddohs.hs
diff options
context:
space:
mode:
authorHendrik Jaeger <henk@frustcomp>2013-12-24 00:14:12 +0100
committerHendrik Jaeger <henk@frustcomp>2013-12-24 00:14:12 +0100
commitd38cc424b83a0240b466f41ec1fe7521aba2d64e (patch)
treeb62a014d8212359974a518e768b6ecf871e33595 /diddohs.hs
parentaa7fd5c65535efa95dd0ea0a320aeac679c6dfa7 (diff)
On branch master
modified: diddohs.hs CHANGED: cleanup and simplification
Diffstat (limited to 'diddohs.hs')
-rw-r--r--diddohs.hs29
1 files changed, 20 insertions, 9 deletions
diff --git a/diddohs.hs b/diddohs.hs
index 60beb31..f54ec2d 100644
--- a/diddohs.hs
+++ b/diddohs.hs
@@ -15,16 +15,27 @@ data DiddoOpts = DiddoOpts
, inFile :: String
}
+calculateDeltas :: [DateTime] -> [Integer]
+calculateDeltas dateTimes = zipWith diffSeconds dateTimes ((startOfDay $ head dateTimes) : init dateTimes)
+
+parseDateTimeFormat :: String -> String -> DateTime
+parseDateTimeFormat format = fromMaybe (error "Input data broken.") . parseDateTime format
+
+startOfDay :: DateTime -> DateTime
+startOfDay = fromJust . parseDateTime "%x" . formatDateTime "%x"
+
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
+mainWithOpts opts =
+ do
+ [ timeStrings
+ , entries
+ ] <- transpose . map (splitOn ";") . lines <$> readFile (inFile opts)
+
+ let
+ deltasHMS = map secondsToHMS $ calculateDeltas $ map (parseDateTimeFormat (inDateFmt opts)) timeStrings
+ diddos_summarized = zipWith4 DiddoEntry ("" : init timeStrings) timeStrings deltasHMS entries
+
+ mapM_ print diddos_summarized
main :: IO ()
main = execParser opts >>= mainWithOpts