Proposal: Use time rather than old-time in directory

Herbert Valerio Riedel hvr at gnu.org
Mon Oct 24 10:10:23 CEST 2011


On Mon, 2011-10-24 at 09:14 +0200, Michael Snoyman wrote:
> > Btw, why do You think UTCTime is more appropriate than POSIXTime?
> >
> > Don't the underlying system calls ({,f,l}stat(2)) actually return
> > `time_t` values for the `st_{a,m,c}time` fields which are supposed to
> > mean "seconds since the Epoch"?
> 
> I'm talking from a library user perspective. I don't think I've once
> used POSIXTime, whereas I use UTCTime regularly. Having to deal with
> just the one type would be very convenient.

I agree it would be convenient to have a `getModificationTime` version
where you don't have to prepend a `liftM 
posixSecondsToUTCTime .` for the cases where you don't care about
leap-seconds ...

> I think your implication is that it will be more efficient to retrieve
> these values as POSIXTime.

that and more importantly the correctness issue of the POSIXTime <->
UTCTime not being bijective in case of leap-seconds, see also

http://en.wikipedia.org/wiki/Unix_time#Encoding_time_as_a_number

for examples where the mapping has discontinuities

I.e., the identities

utcTimeToPOSIXSeconds . posixSecondsToUTCTime = id
posixSecondsToUTCTime . utcTimeToPOSIXSeconds = id

are not supposed to hold (I haven't checked the actual implementation in
the `time` package, so it might currently hold incorrectly hold in the
implementation)

>  If that's the case, maybe it makes sense to
> provide two sets of functions. But I definitely would find it an
> inconvenience to have to deal with POSIXTime myself.

I am in favor for providing also UTCTime wrappers, but I'd definitely
want to be able to work with the "natural" representation POSIXTime, in
order to avoid information loss in cases where this might matter.

E.g., say we get a `setModificationTime` function, then I wouldn't want
to have to transform back and forth to UTCTime, if I had code like
  
  tsave <- getModificationTime fname
  modifyFileSomeWay fname
  setModificationTime fname tsave

I'd want the `time_t` value to be exactly the same it was before the
modification and not risk being shifted by one in case of leap-seconds.
(Or e.g. if I wanted to implement an archiver like `tar` in Haskell, I'd
want the original `time_t` value to be restored)

-- hvr




More information about the Libraries mailing list