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