module Distribution.Hackage.DB.Utility where
import Distribution.Hackage.DB.Errors
import Codec.Archive.Tar.Entry as Tar
import Control.Exception
import Control.Monad.Fail
import Data.Maybe
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Data.Time.Format
import Distribution.Parsec
parseText :: Parsec a => String -> String -> a
parseText :: forall a. Parsec a => String -> String -> a
parseText String
t String
x = forall a. a -> Maybe a -> a
fromMaybe (forall a e. Exception e => e -> a
throw (String -> String -> InvalidRepresentationOfType
InvalidRepresentationOfType String
t String
x)) (forall a. Parsec a => String -> Maybe a
simpleParsec String
x)
fromEpochTime :: EpochTime -> UTCTime
fromEpochTime :: EpochTime -> UTCTime
fromEpochTime EpochTime
et = POSIXTime -> UTCTime
posixSecondsToUTCTime (forall a b. (Real a, Fractional b) => a -> b
realToFrac EpochTime
et)
toEpochTime :: UTCTime -> EpochTime
toEpochTime :: UTCTime -> EpochTime
toEpochTime = forall a b. (RealFrac a, Integral b) => a -> b
floor forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds
parseIso8601 :: MonadFail m => String -> m UTCTime
parseIso8601 :: forall (m :: * -> *). MonadFail m => String -> m UTCTime
parseIso8601 = forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
False TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat (forall a. a -> Maybe a
Just String
"%H:%M:%SZ"))