module Manatee.Toolkit.General.Time where
import Control.Applicative
import Control.Monad
import Data.DateTime hiding (getCurrentTime)
import Data.Time
import System.Glib.GDateTime
import System.Locale
import System.Time
instance Show GTimeVal where
show GTimeVal {gTimeValSec = seconds
,gTimeValUSec = microseconds}
= show seconds ++ " : " ++ show microseconds
getCurrentLocalTime :: IO LocalTime
getCurrentLocalTime = liftM2 utcToLocalTime getCurrentTimeZone getCurrentTime
diffUTCTimeWithSecond :: UTCTime -> UTCTime -> Integer
diffUTCTimeWithSecond t1 t2 = diffUTCTimeWithQuantify t1 t2 1
diffUTCTimeWithMillisecond :: UTCTime -> UTCTime -> Integer
diffUTCTimeWithMillisecond t1 t2 = diffUTCTimeWithQuantify t1 t2 (10 ^ 3)
diffUTCTimeWithMicrosecond :: UTCTime -> UTCTime -> Integer
diffUTCTimeWithMicrosecond t1 t2 = diffUTCTimeWithQuantify t1 t2 (10 ^ 6)
diffUTCTimeWithQuantify :: UTCTime -> UTCTime -> NominalDiffTime -> Integer
diffUTCTimeWithQuantify t1 t2 quantify = truncate $ (quantify *) $ diffUTCTime t1 t2
gTimeValToClockTime :: GTimeVal -> ClockTime
gTimeValToClockTime GTimeVal {gTimeValSec = seconds
,gTimeValUSec = microseconds} =
TOD (toInteger seconds) (toInteger microseconds * 1000)
getTimeStamp :: String -> IO String
getTimeStamp format =
formatTime <$> pure defaultTimeLocale
<*> pure format
<*> (utcToLocalTime <$> getCurrentTimeZone
<*> getCurrentTime)
getSecondsTimeStamp :: Integer -> String -> IO String
getSecondsTimeStamp seconds format =
formatTime <$> pure defaultTimeLocale
<*> pure format
<*> (utcToLocalTime <$> getCurrentTimeZone
<*> pure (fromSeconds seconds))