Skip to content

Instantly share code, notes, and snippets.

@aslatter
Created November 26, 2012 13:14
Show Gist options
  • Select an option

  • Save aslatter/4148129 to your computer and use it in GitHub Desktop.

Select an option

Save aslatter/4148129 to your computer and use it in GitHub Desktop.
getModificationTime shim
{-# LANGUAGE CPP #-}
import Data.Functor ((<$>))
import Data.Time
import System.Directory
#if !(MIN_VERSION_time(1,2,0))
import Data.Time.Clock.POSIX
import System.Time (ClockTime(..))
#endif
getModificationTimeUTC :: FilePath -> IO UTCTime
#if MIN_VERSION_time(1,2,0)
getModificationTimeUTC = getModificationTime
#else
getModificationTimeUTC fp =
clockTimeToUTCTime <$> getModificationTime fp
clockTimeToUTCTime :: ClockTime -> UTCTime
clockTimeToUTCTime (TOD unixTime unixPico) =
let diff = fromInteger unixTime + fromRational ((fromInteger unixPico)/1000000000000)
in posixSecondsToUTCTime diff
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment