From fb819c7f223632dd5baadebbfb6ad6732458390d Mon Sep 17 00:00:00 2001 From: Hendrik Jaeger Date: Tue, 24 Dec 2013 00:09:24 +0100 Subject: On branch master Changes to be committed: new file: Diddo/Entry.hs new file: HMSTime.hs modified: diddohs.hs CHANGED: imports cleanup CHANGED: code for HMSTime and DiddoEntry exported to modules --- Diddo/Entry.hs | 17 +++++++++++++++++ HMSTime.hs | 36 ++++++++++++++++++++++++++++++++++++ diddohs.hs | 20 ++------------------ 3 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 Diddo/Entry.hs create mode 100644 HMSTime.hs diff --git a/Diddo/Entry.hs b/Diddo/Entry.hs new file mode 100644 index 0000000..f6eda25 --- /dev/null +++ b/Diddo/Entry.hs @@ -0,0 +1,17 @@ +module Diddo.Entry +( DiddoEntry(DiddoEntry, start, finish, delta, entry) +) where + +import HMSTime( HMSTime ) +import Data.List( intercalate ) + +data DiddoEntry = DiddoEntry + { start :: String + , finish :: String + , delta :: HMSTime + , entry :: String + } + +instance Show DiddoEntry where + show (DiddoEntry start finish delta entry) = intercalate ";" [start,finish,(show delta),entry] + diff --git a/HMSTime.hs b/HMSTime.hs new file mode 100644 index 0000000..6e903d3 --- /dev/null +++ b/HMSTime.hs @@ -0,0 +1,36 @@ +module HMSTime +( HMSTime(HMSTime, hours, minutes, seconds) +, secondsToHMS +, hmsTimeStringToHMSTime +, hmsTimeStringToSeconds +) where + +import Text.Printf( printf ) +import Data.List.Split( splitOn ) + +data HMSTime = HMSTime { hours :: Integer, minutes :: Integer, seconds :: Integer } + +instance Show HMSTime where + show (HMSTime h m s) = printf "%d:%02d:%02d" h m s + +secondsToHMS :: Integer -> HMSTime +secondsToHMS seconds = HMSTime h m s where + (mLeft, s) = seconds `divMod` 60 + (h, m) = mLeft `divMod` 60 + +hmsTimeStringToHMSTime :: String -> HMSTime +hmsTimeStringToHMSTime hmsString = HMSTime h m s where + h:m:s:_ = map readInteger $ splitOn ":" hmsString + +hmsTimeToSeconds :: HMSTime -> Integer +hmsTimeToSeconds (HMSTime {hours = h, minutes = m, seconds = s}) = h*3600 + m*60 + s + +hmsTimeStringToSeconds :: String -> Integer +hmsTimeStringToSeconds = hmsTimeToSeconds . hmsTimeStringToHMSTime + +hmsIntsToSeconds :: [Int] -> Int +hmsIntsToSeconds (h:m:s:_) = (3600*h + 60*m + s) + +readInteger :: String -> Integer +readInteger x = read x :: Integer + diff --git a/diddohs.hs b/diddohs.hs index 6baa5e9..c9ec405 100644 --- a/diddohs.hs +++ b/diddohs.hs @@ -7,24 +7,8 @@ import Data.Monoid( mempty ) import Data.Time.Clock( secondsToDiffTime ) import Options.Applicative( execParser, info, strOption, long ) import System.Environment( getArgs ) -import Text.Printf( printf ) - -data HMSTime = HMSTime { hours :: Integer, minutes :: Integer, seconds :: Integer } -instance Show HMSTime where - show (HMSTime h m s) = printf "%d:%02d:%02d" h m s - -secondsToHMS :: Integer -> HMSTime -secondsToHMS seconds = HMSTime h m s where - (mLeft, s) = seconds `divMod` 60 - (h, m) = mLeft `divMod` 60 - -data DiddoEntry = DiddoEntry { start :: String - , finish :: String - , delta :: HMSTime - , entry :: String - } -instance Show DiddoEntry where - show (DiddoEntry start finish delta entry) = printf "%s;%s;%s;%s" start finish (show delta) entry +import HMSTime( HMSTime(..), secondsToHMS ) +import Diddo.Entry( DiddoEntry(..) ) data DiddoOpts = DiddoOpts { inDateFmt :: String -- cgit v1.2.3