1 import System.Environment( getArgs )
2 import Data.Time.Git( approxidate )
3 import Data.Time.LocalTime( utcToLocalTime, getTimeZone )
4 import Data.Time.Clock.POSIX( posixSecondsToUTCTime )
5 import Data.List.Split( splitOn )
6 import Data.List( zip4, intersperse )
7 import Data.Maybe( fromJust )
8 import Control.Monad( forM_ )
12 logfile_name : _ <- getArgs
13 logfile_content <- readFile logfile_name
14 let loglines = lines logfile_content
15 loglines_split = map (splitOn ";") loglines
17 entries = map (head . tail) loglines_split
19 timestrings_finish = map head loglines_split
20 timestrings_start = "" : init timestrings_finish
22 timestamps_finish = map timestringToEpoch timestrings_finish
23 timestamps_start = 0 : init timestamps_finish
25 timestamps_deltas = zipWith (-) timestamps_finish timestamps_start
26 timestamps_deltas_HMMSS = map secondsToHMMSS timestamps_deltas
28 delta_entry_tuples = zip timestamps_deltas_HMMSS entries
29 summaries = zip4 (map show timestrings_start) (map show timestrings_finish) timestamps_deltas_HMMSS entries
31 forM_ summaries $ \(start, finish, delta, entry) ->
32 putStrLn $ concat $ intersperse ";" [start, finish, delta, entry]
34 timestringToEpoch :: String -> Integer
35 timestringToEpoch = fromJust . approxidate
37 secondsToHMMSS :: (Num seconds, Show seconds, Integral seconds, Text.Printf.PrintfArg seconds) => seconds -> String
38 secondsToHMMSS seconds = printf "%d:%02d:%02d" h m s
40 (mLeft, s) = seconds `divMod` 60
41 (h, m) = mLeft `divMod` 60
43 getStartOfDay :: Num t => t -> t
44 getStartOfDay time = 0
46 --epochToTimestring :: Num t => t -> String
47 --epochToTimestring epochtime = let getTZ = getTimeZone utctime in utcToLocalTime getTZ utctime
49 -- tz = getTimeZone utctime
50 -- utctime = posixSecondsToUTCTime epochtime