summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--diddohs.hs86
1 files changed, 52 insertions, 34 deletions
diff --git a/diddohs.hs b/diddohs.hs
index fdc1d0d..b96b491 100644
--- a/diddohs.hs
+++ b/diddohs.hs
@@ -1,36 +1,54 @@
-import System.Environment
-import System.IO
-import Options.Applicative
-import Data.Time
-
-data Args = Args
- { entry :: String
--- , time :: Time
--- , verbose :: Bool
--- , file :: String
-}
-
-runWithOptions :: Args -> IO ()
-runWithOptions opts =
- putStrLn ( entry opts ++ " saved." )
-
-main :: IO ()
-main = execParser opts >>= runWithOptions
+import System.Environment( getArgs )
+import Data.Time.Git( approxidate )
+import Data.Time.LocalTime( utcToLocalTime, getTimeZone )
+import Data.Time.Clock.POSIX( posixSecondsToUTCTime )
+import Data.List.Split( splitOn )
+import Data.List( zip4, intersperse )
+import Data.Maybe( fromJust )
+import Control.Monad( forM_ )
+import Text.Printf
+
+main = do
+ logfile_name : _ <- getArgs
+ logfile_content <- readFile logfile_name
+ let loglines = lines logfile_content
+ loglines_split = map (splitOn ";") loglines
+
+ entries = map (head . tail) loglines_split
+
+ timestrings_finish = map head loglines_split
+ timestrings_start = "" : init timestrings_finish
+
+ timestamps_finish = map timestringToEpoch timestrings_finish
+ timestamps_start = 0 : init timestamps_finish
+
+ timestamps_deltas = zipWith (-) timestamps_finish timestamps_start
+ timestamps_deltas_HMMSS = map secondsToHMMSS timestamps_deltas
+
+ delta_entry_tuples = zip timestamps_deltas_HMMSS entries
+ summaries = zip4 (map show timestrings_start) (map show timestrings_finish) timestamps_deltas_HMMSS entries
+
+ forM_ summaries $ \(start, finish, delta, entry) ->
+ putStrLn $ concat $ intersperse ";" [start, finish, delta, entry]
+
+timestringToEpoch :: String -> Integer
+timestringToEpoch = fromJust . approxidate
+
+secondsToHMMSS :: (Num seconds, Show seconds, Integral seconds, Text.Printf.PrintfArg seconds) => seconds -> String
+secondsToHMMSS seconds = printf "%d:%02d:%02d" h m s
where
- parser = Args <$> argument str (metavar "ENTRY")
- opts = info parser mempty
-
--- main = getArgs >>= parse
-
--- parse [] = getLine >>= saveActivity "actlog.txt"
--- parse ["add"] = getLine >>= saveActivity "actlog.txt"
--- parse ["new"] = getLine >>= saveActivity "actlog.txt"
--- parse ("add":entry) = saveActivity "actlog.txt" $ unwords entry
--- parse ("new":entry) = saveActivity "actlog.txt" $ unwords entry
--- parse ("-f":
-
--- saveActivity file act = do
--- zoneTime <- fmap show Data.Time.getZonedTime
--- appendFile "actlog.txt" (zoneTime ++ "\t" ++ act ++ "\n")
--- hPutStrLn stderr ("\"" ++ zoneTime ++ "\t" ++ act ++ "\"" ++ " saved.")
+ (mLeft, s) = seconds `divMod` 60
+ (h, m) = mLeft `divMod` 60
+
+getStartOfDay :: Num t => t -> t
+getStartOfDay time = 0
+
+--epochToTimestring :: Num t => t -> String
+--epochToTimestring epochtime = let getTZ = getTimeZone utctime in utcToLocalTime getTZ utctime
+-- where
+-- tz = getTimeZone utctime
+-- utctime = posixSecondsToUTCTime epochtime
+
+--getTZ time = do
+-- getTimeZone time