{-# LANGUAGE NoImplicitPrelude #-}
module Entwine.Data.Duration (
Duration
, microseconds
, milliseconds
, seconds
, minutes
, hours
, toMicroseconds
, toMilliseconds
, toHours
, toMinutes
, toSeconds
) where
import Entwine.P
newtype Duration =
Duration {
duration :: Int
} deriving (Eq, Show)
microseconds :: Int -> Duration
microseconds =
Duration
milliseconds :: Int -> Duration
milliseconds =
microseconds . (*) 1000
seconds :: Int -> Duration
seconds =
milliseconds . (*) 1000
minutes :: Int -> Duration
minutes =
seconds . (*) 60
hours :: Int -> Duration
hours = minutes . (*) 60
toMicroseconds :: Duration -> Int
toMicroseconds =
duration
toMilliseconds :: Duration -> Int
toMilliseconds =
flip div 1000 . toMicroseconds
toSeconds :: Duration -> Int
toSeconds =
flip div 1000 . toMilliseconds
toMinutes :: Duration -> Int
toMinutes =
flip div 60 . toSeconds
toHours :: Duration -> Int
toHours =
flip div 60 . toMinutes