haskell-github-trust / thyme

A faster date and time library based on time
BSD 3-Clause "New" or "Revised" License
46 stars 33 forks source link

getPOSIXTime usually produces incorrect values #16

Closed pikajude closed 10 years ago

pikajude commented 10 years ago

The struct timeval needs to be zeroed out before use, otherwise tv_usec usually has garbage data in it. Gotta love C!

liyang commented 10 years ago

Are you running on a 32-bit architecture perchance? I was suspicious of the CLongs, but that's what "time" had, even though gettimeofday(2) says they should be time_t and suseconds_t. (Which ought to correspond to CTime and CSUSeconds from Foreign.C.Types.)

Could you try running https://gist.github.com/liyang/10334780 and let me know what it outputs?

pikajude commented 10 years ago
CTime: 8
CUSeconds: 4
CSUSeconds: 4
timeval: 16
tv_sec: 8
tv_usec: 4
(1397092454,985159)

I'm on an early 2013 MBP, running OSX Mavericks which to the best of my knowledge is 64-bit. I don't know why tv_usec is an int instead of a long.