summaryrefslogtreecommitdiff
path: root/HMSTime.hs
diff options
context:
space:
mode:
authorHendrik Jaeger <henk@frustcomp>2014-03-11 00:21:54 +0100
committerHendrik Jaeger <henk@frustcomp>2014-03-11 00:23:04 +0100
commit1e3285599922c3b6ec009ac641464f3232d59bb8 (patch)
tree4b6c4e29f58574182f3b53e327e269d59a1ad0a2 /HMSTime.hs
parent62ba998ef05a79c1fd60386f7ec8dbef49f8a78f (diff)
On branch master
modified: Diddo.hs modified: HMSTime.hs modified: diddohs.hs
Diffstat (limited to 'HMSTime.hs')
-rw-r--r--HMSTime.hs34
1 files changed, 7 insertions, 27 deletions
diff --git a/HMSTime.hs b/HMSTime.hs
index cbe9e09..ce4e3b2 100644
--- a/HMSTime.hs
+++ b/HMSTime.hs
@@ -1,33 +1,13 @@
module HMSTime
-( HMSTime(HMSTime, hours, minutes, seconds)
-, secondsToHMS
-, hmsTimeStringToHMSTime
-, hmsTimeStringToSeconds
+( diffTimeToHMSString
) where
+import Data.Time.Clock( NominalDiffTime() )
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 numSeconds = HMSTime h m s where
- (mLeft, s) = numSeconds `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
-
-readInteger :: String -> Integer
-readInteger x = read x :: Integer
+diffTimeToHMSString :: NominalDiffTime -> String
+diffTimeToHMSString delta = printf "%d:%02d:%02d" h m s
+ where
+ (mLeft, s) = floor delta `divMod` 60 :: (Int, Int)
+ (h, m) = mLeft `divMod` 60