diff options
author | Hendrik Jaeger <henk@frustcomp> | 2013-12-24 00:09:24 +0100 |
---|---|---|
committer | Hendrik Jaeger <henk@frustcomp> | 2013-12-24 00:09:24 +0100 |
commit | fb819c7f223632dd5baadebbfb6ad6732458390d (patch) | |
tree | cc79195f74bb2521469296d52a49e2830039d914 /HMSTime.hs | |
parent | 7bc2168552de76fa7c985b65608199296b6ff55f (diff) |
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
Diffstat (limited to 'HMSTime.hs')
-rw-r--r-- | HMSTime.hs | 36 |
1 files changed, 36 insertions, 0 deletions
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 + |