Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

38 lines (32 sloc) 1.06 kB
module Distribution.Compat.Time where
import Data.Int (Int64)
import System.Directory (getModificationTime)
#if MIN_VERSION_directory(1,2,0)
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds, posixDayLength)
import Data.Time (getCurrentTime, diffUTCTime)
import System.Time (ClockTime(..), getClockTime, diffClockTimes, normalizeTimeDiff, tdDay)
-- | The number of seconds since the UNIX epoch
type EpochTime = Int64
getModTime :: FilePath -> IO EpochTime
getModTime path = do
#if MIN_VERSION_directory(1,2,0)
(truncate . utcTimeToPOSIXSeconds) `fmap` getModificationTime path
(TOD s _) <- getModificationTime path
return $! fromIntegral s
-- | Return age of given file in days.
getFileAge :: FilePath -> IO Int
getFileAge file = do
t0 <- getModificationTime file
#if MIN_VERSION_directory(1,2,0)
t1 <- getCurrentTime
let days = truncate $ (t1 `diffUTCTime` t0) / posixDayLength
t1 <- getClockTime
let days = (tdDay . normalizeTimeDiff) (t1 `diffClockTimes` t0)
return days
Jump to Line
Something went wrong with that request. Please try again.