packages feed

unix-time 0.1.1 → 0.1.2

raw patch · 3 files changed

+126/−6 lines, 3 filesdep +hspec-expectationsdep +old-localedep +test-framework-hunitdep ~base

Dependencies added: hspec-expectations, old-locale, test-framework-hunit, test-framework-th-prime, unix-time

Dependency ranges changed: base

Files

cbits/conv.c view
@@ -1,17 +1,18 @@ #include "config.h" -#include <time.h>-#include <locale.h>- #if IS_LINUX /* Linux cheats AC_CHECK_FUNCS(strptime_l), sigh. */ #define THREAD_SAFE 0 #define _XOPEN_SOURCE+#define _BSD_SOURCE #elif HAVE_STRPTIME_L #define THREAD_SAFE 1 #else #define THREAD_SAFE 0 #endif++#include <time.h>+#include <locale.h>  #if THREAD_SAFE #include <xlocale.h>
+ test/Test.hs view
@@ -0,0 +1,103 @@+{-# LANGUAGE OverloadedStrings, TemplateHaskell #-}++module Main where++import qualified Data.ByteString.Char8 as BS+import Data.UnixTime+import System.Locale+import System.Time hiding (toClockTime)+import Test.Framework.Providers.HUnit+import Test.Framework.TH.Prime+import Test.Hspec.Expectations++----------------------------------------------------------------++main :: IO ()+main = $(defaultMainGenerator)++----------------------------------------------------------------++case_formatUnixTime :: Expectation+case_formatUnixTime = res `shouldBe` ans+  where+    res = formatUnixTime mailDateFormat $ UnixTime 0 0+    ans = "Thu, 01 Jan 1970 09:00:00 +0900"++case_formatUnixTimeGMT :: Expectation+case_formatUnixTimeGMT = res `shouldBe` ans+  where+    res = formatUnixTimeGMT webDateFormat $ UnixTime 0 0+    ans = "Thu, 01 Jan 1970 00:00:00 GMT"++case_parseUnixTime :: Expectation+case_parseUnixTime = res `shouldBe` ans+  where+    res = parseUnixTime mailDateFormat "Thu, 01 Jan 1970 09:00:00 +0900"+    ans = UnixTime 0 0++case_parseUnixTime2 :: Expectation+case_parseUnixTime2 = res `shouldBe` ans+  where+    res = parseUnixTimeGMT webDateFormat "Thu, 01 Jan 1970 00:00:00 GMT"+    ans = UnixTime 0 0++case_formatParse :: Expectation+case_formatParse = do+    ut@(UnixTime sec _) <- getUnixTime+    let ut' = parseUnixTime mailDateFormat $ formatUnixTime mailDateFormat ut+    ut' `shouldBe` UnixTime sec 0++----------------------------------------------------------------++case_fromClockTime :: Expectation+case_fromClockTime = do+    ct <- getClockTime+    let fmt1 = formatUnixTime "%a, %d %b %Y %H:%M:%S" $ fromClockTime ct+    cal <- toCalendarTime ct+    let fmt2 = BS.pack $ formatCalendarTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S" cal+    fmt1 `shouldBe` fmt2++case_toClockTime :: Expectation+case_toClockTime = do+    ut <- getUnixTime+    let fmt1 = formatUnixTime "%a, %d %b %Y %H:%M:%S" ut+        ct = toClockTime ut+    cal <- toCalendarTime ct+    let fmt2 = BS.pack $ formatCalendarTime defaultTimeLocale "%a, %d %b %Y %H:%M:%S" cal+    fmt1 `shouldBe` fmt2++----------------------------------------------------------------++case_diffTime :: Expectation+case_diffTime = do+    ut0 <- getUnixTime+    ut1 <- getUnixTime+    let ut0' = addUnixDiffTime ut1 $ diffUnixTime ut0 ut1+        ut1' = addUnixDiffTime ut0 $ diffUnixTime ut1 ut0+    ut0' `shouldBe` ut0+    ut1' `shouldBe` ut1++----------------------------------------------------------------++case_diffTimeFromSeconds :: Expectation+case_diffTimeFromSeconds = do+    res1 `shouldBe` ans+    res2 `shouldBe` ans+    res3 `shouldBe` ans+  where+    base = parseUnixTime mailDateFormat "Tue, 22 Nov 2011 06:49:58 +0900"+    ans = parseUnixTime mailDateFormat "Tue, 22 Nov 2011 06:50:02 +0900"+    res1 = addUnixDiffTime base 4+    res2 = addUnixDiffTime base (secondsToUnixDiffTime (4 :: Int))+    res3 = addUnixDiffTime base (microSecondsToUnixDiffTime (4000000 :: Int))++----------------------------------------------------------------++case_diffTimeToSeconds :: Expectation+case_diffTimeToSeconds = res `shouldBe` ans+  where+    ans :: Rational+    ans = -12.345678+    res = realToFrac $ microSecondsToUnixDiffTime (-12345678 :: Int)++----------------------------------------------------------------
unix-time.cabal view
@@ -1,5 +1,5 @@ Name:                   unix-time-Version:                0.1.1+Version:                0.1.2 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -7,12 +7,13 @@ Synopsis:               Unix time parser/formatter and utilities Description:            Fast parser\/formatter\/utilities for Unix time Category:               Data-Cabal-Version:          >= 1.6+Cabal-Version:          >= 1.10 Build-Type:             Configure Extra-Source-Files:     cbits/conv.c cbits/config.h.in configure configure.ac Extra-Tmp-Files:        config.log config.status autom4te.cache cbits/config.h -library+Library+  Default-Language:     Haskell2010   GHC-Options:          -Wall   Exposed-Modules:      Data.UnixTime   Other-Modules:        Data.UnixTime.Conv@@ -23,6 +24,21 @@                       , bytestring                       , old-time   C-Sources:            cbits/conv.c++Test-Suite spec+  Type:                 exitcode-stdio-1.0+  Default-Language:     Haskell2010+  Hs-Source-Dirs:       test+  Main-Is:              Test.hs+  GHC-Options:          -Wall+  Build-Depends:        base+                      , bytestring+                      , hspec-expectations+                      , old-locale+                      , old-time+                      , test-framework-hunit+                      , test-framework-th-prime+                      , unix-time  Source-Repository head   Type:                 git