{-# LANGUAGE CPP #-}
module Debian.Time where

import Data.Time
#if !MIN_VERSION_time(1,5,0)
import System.Locale (defaultTimeLocale)
#endif
import Data.Time.Clock.POSIX
import System.Posix.Types

-- * Time Helper Functions

rfc822DateFormat' :: String
rfc822DateFormat' :: String
rfc822DateFormat' = String
"%a, %d %b %Y %T %z"

epochTimeToUTCTime :: EpochTime -> UTCTime
epochTimeToUTCTime :: EpochTime -> UTCTime
epochTimeToUTCTime = POSIXTime -> UTCTime
posixSecondsToUTCTime forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => a -> Int
fromEnum

formatTimeRFC822 :: (FormatTime t) => t -> String
formatTimeRFC822 :: forall t. FormatTime t => t -> String
formatTimeRFC822 = forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
rfc822DateFormat'

parseTimeRFC822 :: (ParseTime t) => String -> Maybe t
parseTimeRFC822 :: forall t. ParseTime t => String -> Maybe t
parseTimeRFC822 = forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale String
rfc822DateFormat'

getCurrentLocalRFC822Time :: IO String
getCurrentLocalRFC822Time :: IO String
getCurrentLocalRFC822Time = IO UTCTime
getCurrentTime forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> IO ZonedTime
utcToLocalZonedTime forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
rfc822DateFormat'