[Haskell-cafe] Working with multiple time zones

Ryan Ingram ryani.spam at gmail.com
Sat Feb 16 20:25:25 EST 2008


I don't have anything to answer for the "interesting" part of your
question, but if you're just interested in getting something
working...

On Feb 16, 2008 3:13 PM, Dave Hinton <beakerchu at googlemail.com> wrote:
> 2. If GHC's implementation is working as designed, how do I translate
> the C program above into Haskell?

You can use the FFI to call localtime() directly; see
http://www.haskell.org/haskellwiki/FFI_Introduction
There's information on the types to use here:
http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-C.html
http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign.html

Something along the lines of:

{-# LANGUAGE FFI #-}
{-# INCLUDE <time.h> #-}
import Foreign
import Foreign.C

data CStructTm = ... -- implement struct tm here
instance Storable CStructTm where ...

foreign import ccall unsafe "localtime" c_localtime :: Ptr CTime -> IO
(Ptr CStructTm)

localtime :: CTime -> IO CStructTm
localtime = do ... -- marshal time into a pointer, call c_localtime,
marshal structure back into a CStructTm and return it.


More information about the Haskell-Cafe mailing list