2 ( HMSTime(HMSTime, hours, minutes, seconds)
4 , hmsTimeStringToHMSTime
5 , hmsTimeStringToSeconds
8 import Text.Printf( printf )
9 import Data.List.Split( splitOn )
11 data HMSTime = HMSTime { hours :: Integer, minutes :: Integer, seconds :: Integer }
13 instance Show HMSTime where
14 show (HMSTime h m s) = printf "%d:%02d:%02d" h m s
16 secondsToHMS :: Integer -> HMSTime
17 secondsToHMS seconds = HMSTime h m s where
18 (mLeft, s) = seconds `divMod` 60
19 (h, m) = mLeft `divMod` 60
21 hmsTimeStringToHMSTime :: String -> HMSTime
22 hmsTimeStringToHMSTime hmsString = HMSTime h m s where
23 h:m:s:_ = map readInteger $ splitOn ":" hmsString
25 hmsTimeToSeconds :: HMSTime -> Integer
26 hmsTimeToSeconds (HMSTime {hours = h, minutes = m, seconds = s}) = h*3600 + m*60 + s
28 hmsTimeStringToSeconds :: String -> Integer
29 hmsTimeStringToSeconds = hmsTimeToSeconds . hmsTimeStringToHMSTime
31 hmsIntsToSeconds :: [Int] -> Int
32 hmsIntsToSeconds (h:m:s:_) = (3600*h + 60*m + s)
34 readInteger :: String -> Integer
35 readInteger x = read x :: Integer