packages feed

thyme 0.3.2.0 → 0.3.3.0

raw patch · 9 files changed

+62/−24 lines, 9 files

Files

src/Data/Thyme/Calendar/Internal.hs view
@@ -20,6 +20,7 @@ import Control.Lens import Control.Monad import Data.AffineSpace+import Data.Bits ((.&.)) import Data.Data import Data.Int import Data.Ix@@ -27,10 +28,8 @@ import Data.Vector.Unboxed (Vector) import qualified Data.Vector.Unboxed as V import GHC.Generics (Generic)-import GHC.Prim-import GHC.Types import System.Random-import Test.QuickCheck+import Test.QuickCheck hiding ((.&.))  type Years = Int type Months = Int@@ -105,13 +104,8 @@  -- | Gregorian leap year? isLeapYear :: Year -> Bool-isLeapYear (I# y#) = isLeapYear# y#---- | INTERNAL: avoid GHC duplicating code for each of the possibilities.-{-# NOINLINE isLeapYear# #-}-isLeapYear# :: Int# -> Bool-isLeapYear# y# = remInt# y# 4# ==# 0#-    && (remInt# y# 400# ==# 0# || remInt# y# 100# /=# 0#)+isLeapYear y = y .&. 3 == 0 && (r100 /= 0 || q100 .&. 3 == 0) where+    (q100, r100) = y `quotRem` 100  type DayOfYear = Int data OrdinalDate = OrdinalDate
src/Data/Thyme/Clock/Internal.hs view
@@ -52,7 +52,7 @@ -- -- [@Performance@] Try to make sure @n@ is one of 'Float', 'Double', 'Int', -- 'Int64' or 'Integer', for which rewrite @RULES@ have been provided.-{-# INLINE fromSeconds #-}+{-# INLINE[0] fromSeconds #-} fromSeconds :: (Real n, TimeDiff t) => n -> t fromSeconds = fromSeconds' . toRational @@ -77,11 +77,11 @@  {-# RULES -"fromSeconds/Float"     fromSeconds = fromSecondsRealFrac (0 :: Float)-"fromSeconds/Double"    fromSeconds = fromSecondsRealFrac (0 :: Double)-"fromSeconds/Int"       fromSeconds = fromSecondsIntegral (0 :: Int)-"fromSeconds/Int64"     fromSeconds = fromSecondsIntegral (0 :: Int64)-"fromSeconds/Integer"   fromSeconds = fromSecondsIntegral (0 :: Integer)+"fromSeconds/Float"    [~0] fromSeconds = fromSecondsRealFrac (0 :: Float)+"fromSeconds/Double"   [~0] fromSeconds = fromSecondsRealFrac (0 :: Double)+"fromSeconds/Int"      [~0] fromSeconds = fromSecondsIntegral (0 :: Int)+"fromSeconds/Int64"    [~0] fromSeconds = fromSecondsIntegral (0 :: Int64)+"fromSeconds/Integer"  [~0] fromSeconds = fromSecondsIntegral (0 :: Integer)    #-} 
src/Data/Thyme/Clock/POSIX.hsc view
@@ -38,17 +38,22 @@ getPOSIXTime :: IO POSIXTime #ifdef mingw32_HOST_OS +-- On Windows, the equlvalent of POSIX time is "file time", defined as+-- the number of 100-nanosecond intervals that have elapsed since+-- 12:00 AM January 1, 1601 (UTC). We can convert this into a POSIX+-- time by adjusting the offset to be relative to the POSIX epoch. getPOSIXTime = do     FILETIME ft <- System.Win32.Time.getSystemTimeAsFileTime-    return . NominalDiffTime . Micro $-        fromIntegral ft - 116444736000000000{-win32_epoch_adjust-}+    return . NominalDiffTime . Micro . fromIntegral $+        quot ft 10 - 11644473600000000{-ftEpoch ^. microseconds-}+--  ftEpoch = utcTime # UTCTime (gregorian # YearMonthDay 1601 1 1) zeroV  #else  getPOSIXTime = allocaBytes #{size struct timeval} $ \ ptv -> do     throwErrnoIfMinus1_ "gettimeofday" $ gettimeofday ptv nullPtr-    sec <- #{peek struct timeval, tv_sec} ptv :: IO CLong-    usec <- #{peek struct timeval, tv_usec} ptv :: IO CLong+    CTime sec <- #{peek struct timeval, tv_sec} ptv+    CSUSeconds usec <- #{peek struct timeval, tv_usec} ptv     return . NominalDiffTime . Micro $         1000000 * fromIntegral sec + fromIntegral usec 
src/Data/Thyme/LocalTime.hs view
@@ -63,7 +63,7 @@         (minutes, g1) = randomR (timeZoneMinutes l, timeZoneMinutes u) g0         (summer, g2) = randomR (timeZoneSummerOnly l, timeZoneSummerOnly u) g1         -- slightly dubious interpretation of ‘range’-        (name, g3) = foldr randChar ([], g2) . take 4 $ zipWith (,)+        (name, g3) = foldr randChar ([], g2) . take 4 $ zip             (timeZoneName l ++ "AAAA") (timeZoneName u ++ "ZZZZ")         randChar nR (ns, g) = (: ns) `first` randomR nR g     random = randomR (minBound, maxBound)
src/Data/Thyme/Time/Core.hs view
@@ -252,6 +252,14 @@ diffUTCTime :: UTCTime -> UTCTime -> NominalDiffTime diffUTCTime = (.-.) +{-# INLINE toMicroseconds #-}+toMicroseconds :: (TimeDiff t) => t -> Int64+toMicroseconds = view microseconds++{-# INLINE fromMicroseconds #-}+fromMicroseconds :: (TimeDiff t) => Int64 -> t+fromMicroseconds = review microseconds+ ------------------------------------------------------------------------ -- * @Data.Time.Clock.POSIX@ 
tests/Common.hs view
@@ -5,6 +5,7 @@ import Control.Applicative import Control.Lens import Data.AdditiveGroup+import Data.Char import Data.Thyme import Data.Thyme.Clock.POSIX import System.Exit@@ -56,7 +57,7 @@             -- , (2, pure $ spec {-aggregate-}"crXx")             , (1, pure $ spec {-UTCTime-}"s")             ] :: Gen (Gen String)-        fmap (Spec . unwords) . listOf1 $ frequency+        fmap (Spec . dropWhile isSpace . unwords) . listOf1 $ frequency             [(16, time), (4, string), (1, pure "%%")]       where         spec = Gen.elements . fmap (\ c -> ['%', c])
tests/bench.hs view
@@ -1,3 +1,9 @@+{-# LANGUAGE CPP #-}++#if HLINT+#include "cabal_macros.h"+#endif+ import Prelude import Control.Arrow import Control.Applicative@@ -21,9 +27,14 @@ import qualified Data.Time.Clock.POSIX as T import Test.QuickCheck as QC import Test.QuickCheck.Gen as QC+#if MIN_VERSION_QuickCheck(2,7,0)+import Test.QuickCheck.Random as QC+#endif import System.Locale +#if !MIN_VERSION_QuickCheck(2,7,0) import System.Random+#endif import Text.Printf  import Common@@ -31,7 +42,12 @@ {-# ANN main "HLint: ignore Use list literal" #-} main :: IO () main = do-    utcs <- unGen (vectorOf samples arbitrary) <$> newStdGen <*> pure 0+    utcs <- unGen (vectorOf samples arbitrary)+#if MIN_VERSION_QuickCheck(2,7,0)+        <$> QC.newQCGen <*> pure 0+#else+        <$> newStdGen <*> pure 0+#endif     let utcs' = review thyme <$> (utcs :: [UTCTime])     now <- getCurrentTime     let now' = thyme # now@@ -40,6 +56,8 @@     let dt' = thyme # dt     let days = utctDay . unUTCTime <$> utcs     let days' = T.utctDay <$> utcs'+    let years = view (gregorian . _ymdYear) <$> days+    let years' = (\ (y, _m, _d) -> y) . T.toGregorian <$> days'     let mons = ((isLeapYear . ymdYear) &&& ymdMonth) . view gregorian <$> days     let ords = ((isLeapYear . odYear) &&& odDay) . view ordinalDate <$> days @@ -77,6 +95,10 @@             ( "dayOfYearToMonthAndDay", 4.3                 , nf (uncurry dayOfYearToMonthAndDay <$>) ords                 , nf (uncurry T.dayOfYearToMonthAndDay <$>) ords ) :++            ( "isLeapYear", 1.5+                , nf (isLeapYear <$>) years+                , nf (T.isLeapYear <$>) years' ) :              -- Clock             ( "addUTCTime", 85
tests/sanity.hs view
@@ -42,14 +42,22 @@  prop_formatTime :: Spec -> RecentTime -> Property prop_formatTime (Spec spec) (RecentTime t@(review thyme -> t'))+#if MIN_VERSION_QuickCheck(2,7,0)+        = counterexample desc (s == s') where+#else         = printTestCase desc (s == s') where+#endif     s = formatTime defaultTimeLocale spec t     s' = T.formatTime defaultTimeLocale spec t'     desc = "thyme: " ++ s ++ "\ntime:  " ++ s'  prop_parseTime :: Spec -> RecentTime -> Property prop_parseTime (Spec spec) (RecentTime orig)+#if MIN_VERSION_QuickCheck(2,7,0)+        = counterexample desc (fmap (review thyme) t == t') where+#else         = printTestCase desc (fmap (review thyme) t == t') where+#endif     s = T.formatTime defaultTimeLocale spec (thyme # orig)     t = parseTime defaultTimeLocale spec s :: Maybe UTCTime     t' = T.parseTime defaultTimeLocale spec s
thyme.cabal view
@@ -1,5 +1,5 @@ name:           thyme-version:        0.3.2.0+version:        0.3.3.0 synopsis:       A faster time library description:     Thyme is a rewrite of the fine @time@ library, with a particular focus