[Haskell-cafe] Re: Can't do basic time operations with System.Time

Peter Simons simons at cryp.to
Fri Jan 21 13:08:29 EST 2005


John Goerzen writes:

 > timeDiffToSecs :: TimeDiff -> Integer
 > timeDiffToSecs td =
 >     (fromIntegral $ tdSec td) +
 >     60 * ((fromIntegral $ tdMin td) +
 >           60 * ((fromIntegral $ tdHour td) +
 >                 24 * ((fromIntegral $ tdDay td) +
 >                       30 * ((fromIntegral $ tdMonth td) +
 >                             365 * (fromIntegral $ tdYear td)))))

I was wondering: Does this calculation account for leap
years? Does it have to?

As I see it, it's not possible to convert a TimeDiff
accurately without knowing the point in time from which to
"diff" from. How many days is "4 years from now"? It's almost
certainly not 4*365 days.

Uh, did I mention leap seconds? ;-)

Peter



More information about the Haskell-Cafe mailing list