hourglass 0.2.3 → 0.2.4
raw patch · 4 files changed
+59/−4 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Hourglass/Types.hs +19/−2
- README.md +5/−0
- hourglass.cabal +1/−1
- tests/Tests.hs +34/−1
Data/Hourglass/Types.hs view
@@ -122,13 +122,30 @@ instance NFData ElapsedP where rnf e = e `seq` () instance Num ElapsedP where- (ElapsedP e1 ns1) + (ElapsedP e2 ns2) = ElapsedP (e1+e2) (ns1+ns2)- (ElapsedP e1 ns1) - (ElapsedP e2 ns2) = ElapsedP (e1-e2) (ns1-ns2)+ (+) = addElapsedP+ (-) = subElapsedP (ElapsedP e1 ns1) * (ElapsedP e2 ns2) = ElapsedP (e1*e2) (ns1*ns2) negate (ElapsedP e ns) = ElapsedP (negate e) ns abs (ElapsedP e ns) = ElapsedP (abs e) ns signum (ElapsedP e ns) = ElapsedP (signum e) ns fromInteger i = ElapsedP (Elapsed (fromIntegral i)) 0++addElapsedP :: ElapsedP -> ElapsedP -> ElapsedP+addElapsedP (ElapsedP e1 (NanoSeconds ns1)) (ElapsedP e2 (NanoSeconds ns2)) =+ let notNormalizedNS = ns1 + ns2+ (retainedNS, ns) = notNormalizedNS `divMod` 1000000000+ in ElapsedP (e1 + e2 + (Elapsed $ Seconds retainedNS)) (NanoSeconds ns)++subElapsedP :: ElapsedP -> ElapsedP -> ElapsedP+subElapsedP (ElapsedP e1 (NanoSeconds ns1)) (ElapsedP e2 (NanoSeconds ns2)) =+ let notNormalizedNS = ns1 - ns2+ notNormalizedS = e1 - e2+ in if notNormalizedNS < 0+ then ElapsedP (notNormalizedS - oneSecond) (NanoSeconds (1000000000 + notNormalizedNS))+ else ElapsedP notNormalizedS (NanoSeconds notNormalizedNS)+ where+ oneSecond :: Elapsed+ oneSecond = Elapsed $ Seconds 1 instance Real ElapsedP where -- FIXME
README.md view
@@ -1,5 +1,10 @@ hourglass =========++[](https://travis-ci.org/vincenthz/hs-hourglass)+[](http://en.wikipedia.org/wiki/BSD_licenses)+[](http://haskell.org)+ Hourglass is a simple time library. Documentation: [hourglass on hackage](http://hackage.haskell.org/package/hourglass)
hourglass.cabal view
@@ -1,5 +1,5 @@ Name: hourglass-Version: 0.2.3+Version: 0.2.4 Synopsis: simple performant time related library Description: Simple time library focusing on simple but powerful and performant API
tests/Tests.hs view
@@ -110,6 +110,37 @@ | expected == got = True | otherwise = error ("expected: " ++ show expected ++ " got: " ++ show got) +testCaseWith :: (Num a, Eq a, Show a) => String -> (a -> a -> a) -> (a, a, a) -> TestTree+testCaseWith what fun (x, y, ref) =+ testCase ((show x) ++ " " ++ what ++ " " ++ (show y) ++ " ?= " ++ (show ref)) checkAdd+ where+ checkAdd :: Assertion+ checkAdd =+ if fun x y /= ref+ then assertFailure $ (show $ fun x y) ++ " /= " ++ (show ref)+ else return ()++arithmeticTestAddRef :: [(ElapsedP, ElapsedP, ElapsedP)]+arithmeticTestAddRef = map testRefToElapsedP+ [ ((1, 090000000), (2, 090000000), (3, 180000000))+ , ((1, 900000000), (1, 200000000), (3, 100000000))+ , ((1, 000000001), (0, 999999999), (2, 000000000))+ ]++arithmeticTestSubRef :: [(ElapsedP, ElapsedP, ElapsedP)]+arithmeticTestSubRef = map testRefToElapsedP+ [ ((1, 100000000), (1, 100000000), (0, 000000000))+ , ((1, 900000000), (1, 100000000), (0, 800000000))+ , ((1, 100000000), (0, 200000000), (0, 900000000))+ , ((1, 100000000), (2, 400000000), (-2, 700000000))+ ]++testRefToElapsedP :: ((Int64, Int64), (Int64, Int64), (Int64, Int64)) -> (ElapsedP, ElapsedP, ElapsedP)+testRefToElapsedP (a, b, c) = (tupleToElapsedP a, tupleToElapsedP b, tupleToElapsedP c) + where+ tupleToElapsedP :: (Int64, Int64) -> ElapsedP+ tupleToElapsedP (s, n) = ElapsedP (Elapsed $ Seconds s) (NanoSeconds n)+ tests knowns = testGroup "hourglass" [ testGroup "known" [ testGroup "calendar conv" (map toCalendarTest $ zip eint (map tuple12 knowns))@@ -132,7 +163,9 @@ in localTimeToGlobal l `eq` localTimeToGlobal l2 ] , testGroup "arithmetic"- [ {-testProperty "add-diff" $ \(e :: Elapsed, tdiff) ->+ [ testGroup "ElapseP add" $ map (testCaseWith "+" (+)) arithmeticTestAddRef+ , testGroup "ElapseP sub" $ map (testCaseWith "-" (-)) arithmeticTestSubRef+ {-testProperty "add-diff" $ \(e :: Elapsed, tdiff) -> let d@(TimeDiff _ _ day h mi s _) = tdiff { timeDiffYears = 0 , timeDiffMonths = 0 , timeDiffNs = 0