packages feed

unix-time 0.2.0 → 0.2.1

raw patch · 4 files changed

+62/−37 lines, 4 files

Files

− Data/UnixTime/Types.hs
@@ -1,36 +0,0 @@-module Data.UnixTime.Types where--import Data.ByteString-import Data.ByteString.Char8 ()-import Data.Int-import Foreign.C.Types---- |--- Data structure for Unix time.-data UnixTime = UnixTime {-    -- | Seconds from 1st Jan 1970-    utSeconds :: {-# UNPACK #-} !CTime-    -- | Micro seconds (i.e. 10^(-6))-  , utMicroSeconds :: {-# UNPACK #-} !Int32-  } deriving (Eq,Ord,Show)---- |--- Format of the strptime()/strftime() style.-type Format = ByteString---- |--- Data structure for UnixTime diff.------ >>> (3 :: UnixDiffTime) + 2--- UnixDiffTime {udtSeconds = 5, udtMicroSecnods = 0}--- >>> (2 :: UnixDiffTime) - 5--- UnixDiffTime {udtSeconds = -3, udtMicroSecnods = 0}--- >>> (3 :: UnixDiffTime) * 2--- UnixDiffTime {udtSeconds = 6, udtMicroSecnods = 0}--data UnixDiffTime = UnixDiffTime {-    -- | Seconds from 1st Jan 1970-    udtSeconds :: {-# UNPACK #-} !CTime-    -- | Micro seconds (i.e. 10^(-6))-  , udtMicroSecnods :: {-# UNPACK #-} !Int32-  } deriving (Eq,Ord,Show)
+ Data/UnixTime/Types.hsc view
@@ -0,0 +1,52 @@+module Data.UnixTime.Types where++import Control.Applicative ((<$>), (<*>))+import Data.ByteString+import Data.ByteString.Char8 ()+import Data.Int+import Foreign.C.Types+import Foreign.Storable++#include <sys/time.h>++#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)++-- |+-- Data structure for Unix time.+data UnixTime = UnixTime {+    -- | Seconds from 1st Jan 1970+    utSeconds :: {-# UNPACK #-} !CTime+    -- | Micro seconds (i.e. 10^(-6))+  , utMicroSeconds :: {-# UNPACK #-} !Int32+  } deriving (Eq,Ord,Show)++instance Storable UnixTime where+    sizeOf _    = (#size struct timeval)+    alignment _ = (#alignment struct timeval)+    peek ptr    = UnixTime+            <$> (#peek struct timeval, tv_sec)  ptr+            <*> (#peek struct timeval, tv_usec) ptr+    poke ptr ut = do+            (#poke struct timeval, tv_sec)  ptr (utSeconds ut)+            (#poke struct timeval, tv_usec) ptr (utMicroSeconds ut)++-- |+-- Format of the strptime()/strftime() style.+type Format = ByteString++-- |+-- Data structure for UnixTime diff.+--+-- >>> (3 :: UnixDiffTime) + 2+-- UnixDiffTime {udtSeconds = 5, udtMicroSecnods = 0}+-- >>> (2 :: UnixDiffTime) - 5+-- UnixDiffTime {udtSeconds = -3, udtMicroSecnods = 0}+-- >>> (3 :: UnixDiffTime) * 2+-- UnixDiffTime {udtSeconds = 6, udtMicroSecnods = 0}++data UnixDiffTime = UnixDiffTime {+    -- | Seconds from 1st Jan 1970+    udtSeconds :: {-# UNPACK #-} !CTime+    -- | Micro seconds (i.e. 10^(-6))+  , udtMicroSecnods :: {-# UNPACK #-} !Int32+  } deriving (Eq,Ord,Show)
test/UnixTimeSpec.hs view
@@ -8,6 +8,9 @@ import Data.Time import Data.Time.Clock.POSIX (posixSecondsToUTCTime) import Data.UnixTime+import Foreign.Ptr (Ptr)+import Foreign.Marshal.Alloc (alloca)+import Foreign.Storable (peek, poke) import System.Locale (defaultTimeLocale) import Test.Hspec import Test.Hspec.QuickCheck (prop)@@ -48,6 +51,12 @@             let ut0' = addUnixDiffTime ut1 $ diffUnixTime ut0 ut1                 ut1' = addUnixDiffTime ut0 $ diffUnixTime ut1 ut0             in ut0' == ut0 && ut1' == ut1++    describe "UnixTime Storable instance" $+        prop "peek . poke = id" $ \ut ->+            let pokePeek :: Ptr UnixTime -> IO UnixTime+                pokePeek ptr = poke ptr ut >> peek ptr+            in shouldReturn (alloca pokePeek) ut  formatMailModel :: UTCTime -> TimeZone -> ByteString formatMailModel ut zone = BS.pack $ formatTime defaultTimeLocale fmt zt
unix-time.cabal view
@@ -1,5 +1,5 @@ Name:                   unix-time-Version:                0.2.0+Version:                0.2.1 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3