I am trying to load timestamps into mysql. All my times are UTCTime objects. The HDBC mysql implementation does not seem to like UTCTime objects although internally the documentation says that it treats all times as if they were UTC times. I believe that I need to convert UTCTime to EpochTime since it looks like the HDBC mysql implementation supports binding SqlEpochTime. I have not been able to figure out how to take my UTCTime and get an EpochTime out of it.
+3
A:
Here's a workaround for now:
import Data.Time.Clock (UTCTime)
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
import Database.HDBC (SqlValue (SqlEpochTime))
-- until HDBC-mysql fixes it. use instead of SqlUTCTime (data constructor)
sqlUTCTime :: UTCTime -> SqlValue
sqlUTCTime = SqlEpochTime . floor . utcTimeToPOSIXSeconds
I sent Chris Waterson (HDBC-mysql's mainainer) a fix 3 weeks ago and he said that he'll incorporate it into the next version.
yairchu
2010-07-12 17:39:38