getModificationTime and directory-1.2

Hi, directory 1.2 switches to being based on 'time' rather than 'old-time'. Because time values are exposed in its external API, this is causing some disruption. In particular something like this pattern seems relatively common: getModTime :: FilePath -> IO EpochTime getModTime path = do (TOD s _) <- getModificationTime path return $! fromIntegral s i.e. get the modification time of a file in seconds since the UNIX epoch. The replacement is something like: t <- getModificationTime path return $! fromInteger $ floor $ t `diffUTCTime` UTCTime (fromGregorian 1970 1 1) 0 But if you want to be backwards compatible then cabal flags and CPP are needed, so it's all a bit verbose. Amongst the dependencies of darcs, I've found myself making a similar change to three packages now (unix-compat, tar, zip-archive), so I wonder if it's worth putting this function somewhere central? One problem is that it's too late to put it in directory, because 1.2.0.0 was shipped with ghc 7.6.1 and so packages need to work against that version. How do people feel about a small package, e.g. 'directory-time' or 'modtime'? Or is there some cleaner workaround that I've missed? Cheers, Ganesh

On Wed, Sep 12, 2012 at 07:04:18AM +0100, Ganesh Sittampalam wrote:
The replacement is something like:
t <- getModificationTime path return $! fromInteger $ floor $ t `diffUTCTime` UTCTime (fromGregorian 1970 1 1) 0
Not sure if it makes any difference, but I use: floor . utcTimeToPOSIXSeconds <$> getModificationTime path Cheers, Simon

On 12/09/2012 07:28, Simon Hengel wrote:
On Wed, Sep 12, 2012 at 07:04:18AM +0100, Ganesh Sittampalam wrote:
The replacement is something like:
t <- getModificationTime path return $! fromInteger $ floor $ t `diffUTCTime` UTCTime (fromGregorian 1970 1 1) 0
Not sure if it makes any difference, but I use:
floor . utcTimeToPOSIXSeconds <$> getModificationTime path
Thanks, that's much nicer. I missed utcTimeToPOSIXSeconds. Since there hasn't been any support for the idea of the separate package, I think I'll default to submitting patches for conditional compilation to each affected project, and only make the separate packages if the maintainers are keen. Ganesh
participants (2)
-
Ganesh Sittampalam
-
Simon Hengel