unix-time 0.1.9 → 0.1.10
raw patch · 4 files changed
+33/−22 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.UnixTime: formatUnixTime :: Format -> UnixTime -> ByteString
+ Data.UnixTime: formatUnixTime :: Format -> UnixTime -> IO ByteString
Files
- Data/UnixTime/Conv.hs +25/−14
- cbits/conv.c +6/−6
- test/UnixTimeSpec.hs +1/−1
- unix-time.cabal +1/−1
Data/UnixTime/Conv.hs view
@@ -8,6 +8,7 @@ , fromClockTime, toClockTime ) where +import Control.Applicative import Data.ByteString import Data.ByteString.Unsafe import Data.UnixTime.Types@@ -25,10 +26,10 @@ c_parse_unix_time_gmt :: CString -> CString -> IO CTime foreign import ccall unsafe "c_format_unix_time"- c_format_unix_time :: CString -> CTime -> CString -> CInt -> IO ()+ c_format_unix_time :: CString -> CTime -> CString -> CInt -> IO CSize foreign import ccall unsafe "c_format_unix_time_gmt"- c_format_unix_time_gmt :: CString -> CTime -> CString -> CInt -> IO ()+ c_format_unix_time_gmt :: CString -> CTime -> CString -> CInt -> IO CSize ---------------------------------------------------------------- @@ -64,13 +65,10 @@ -- Formatting 'UnixTime' to 'ByteString' in local time. -- This is a wrapper for strftime_l(). -formatUnixTime :: Format -> UnixTime -> ByteString-formatUnixTime fmt (UnixTime sec _) = unsafePerformIO $- useAsCString fmt $ \cfmt -> do- let siz = 256 -- FIXME- ptr <- mallocBytes siz- c_format_unix_time cfmt sec ptr (fromIntegral siz)- unsafePackMallocCString ptr+formatUnixTime :: Format -> UnixTime -> IO ByteString+formatUnixTime fmt t =+ formatUnixTimeHelper c_format_unix_time fmt t+{-# INLINE formatUnixTime #-} -- | -- Formatting 'UnixTime' to 'ByteString' in GMT.@@ -80,12 +78,25 @@ -- "Thu, 01 Jan 1970 00:00:00 GMT" formatUnixTimeGMT :: Format -> UnixTime -> ByteString-formatUnixTimeGMT fmt (UnixTime sec _) = unsafePerformIO $+formatUnixTimeGMT fmt t =+ unsafePerformIO $ formatUnixTimeHelper c_format_unix_time_gmt fmt t+{-# INLINE formatUnixTimeGMT #-}++-- |+-- Helper handling memory allocation for formatUnixTime and formatUnixTimeGMT.++formatUnixTimeHelper+ :: (CString -> CTime -> CString -> CInt -> IO CSize)+ -> Format+ -> UnixTime+ -> IO ByteString+formatUnixTimeHelper formatFun fmt (UnixTime sec _) = useAsCString fmt $ \cfmt -> do- let siz = 256 -- FIXME- ptr <- mallocBytes siz- c_format_unix_time_gmt cfmt sec ptr (fromIntegral siz)- unsafePackMallocCString ptr+ let siz = 80+ ptr <- mallocBytes siz+ len <- fromIntegral <$> formatFun cfmt sec ptr (fromIntegral siz)+ ptr' <- reallocBytes ptr (len + 1)+ unsafePackMallocCString ptr' -- FIXME: Use unsafePackMallocCStringLen from bytestring-0.10.2.0 ----------------------------------------------------------------
cbits/conv.c view
@@ -58,24 +58,24 @@ return timegm(&dst); } -void c_format_unix_time(char *fmt, time_t src, char* dst, int siz) {+size_t c_format_unix_time(char *fmt, time_t src, char* dst, int siz) { struct tm tim; init_locale(); localtime_r(&src, &tim); #if THREAD_SAFE- strftime_l(dst, siz, fmt, &tim, c_locale);+ return strftime_l(dst, siz, fmt, &tim, c_locale); #else- strftime(dst, siz, fmt, &tim);+ return strftime(dst, siz, fmt, &tim); #endif } -void c_format_unix_time_gmt(char *fmt, time_t src, char* dst, int siz) {+size_t c_format_unix_time_gmt(char *fmt, time_t src, char* dst, int siz) { struct tm tim; init_locale(); gmtime_r(&src, &tim); #if THREAD_SAFE- strftime_l(dst, siz, fmt, &tim, c_locale);+ return strftime_l(dst, siz, fmt, &tim, c_locale); #else- strftime(dst, siz, fmt, &tim);+ return strftime(dst, siz, fmt, &tim); #endif }
test/UnixTimeSpec.hs view
@@ -34,7 +34,7 @@ utcTime = toUTCTime ut timeZone <- getTimeZone utcTime let model = formatMailModel utcTime timeZone- ours `shouldBe` model+ ours `shouldReturn` model describe "parseUnixTimeGMT & formatUnixTimeGMT" $ prop "inverses the result" $ \ut@(UnixTime sec _) ->
unix-time.cabal view
@@ -1,5 +1,5 @@ Name: unix-time-Version: 0.1.9+Version: 0.1.10 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3