hora 1.0.2 → 1.0.3
raw patch · 6 files changed
+100/−6 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Time.Hora.Type.Time: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Time.Hora.Type.Time.TimeSpan a)
- Data.Time.Hora.Type.Time: instance GHC.Classes.Ord a => GHC.Classes.Ord (Data.Time.Hora.Type.Time.TimeSpan a)
+ Data.Time.Hora.Type.Time: instance (GHC.Classes.Eq a, GHC.Real.Integral a) => GHC.Classes.Eq (Data.Time.Hora.Type.Time.TimeSpan a)
+ Data.Time.Hora.Type.Time: instance (GHC.Classes.Ord a, GHC.Real.Integral a) => GHC.Classes.Ord (Data.Time.Hora.Type.Time.TimeSpan a)
+ Data.Time.Hora.Type.Time: instance GHC.Base.Functor Data.Time.Hora.Type.Time.TimeSpan
+ Data.Time.Hora.Type.Time: instance GHC.Real.Integral a => GHC.Num.Num (Data.Time.Hora.Type.Time.TimeSpan a)
Files
- README.md +11/−0
- changelog.md +5/−0
- hora.cabal +2/−2
- src/Data/Time/Hora/Convert.hs +1/−0
- src/Data/Time/Hora/Type/Time.hs +69/−4
- test/Test/TestConvert.hs +12/−0
+ README.md view
@@ -0,0 +1,11 @@+### hora++ convenience date, time types and functions+ + timestamps+ + parse UTCTime to explicit type+ + time in future + + pico difference between times
changelog.md view
@@ -1,3 +1,8 @@+##### 1.0.3+ fix Eq, Ord TimeSpan: was derived. Implemented manually+ + add Num TimeSpan + ##### 1.0.2 Tz derive Functor
hora.cabal view
@@ -1,5 +1,5 @@ name: hora-version: 1.0.2+version: 1.0.3 build-type: Simple cabal-version: >=1.10 @@ -10,7 +10,7 @@ category: System, Time license: PublicDomain license-file: PublicDomain-extra-source-files: changelog.md+extra-source-files: changelog.md, README.md homepage: https://github.com/ciez/hora source-repository head
src/Data/Time/Hora/Convert.hs view
@@ -59,3 +59,4 @@ nominalDiff::Integral a => TimeSpan a -> NominalDiffTime nominalDiff ts0 = let s1 = toPico ts0::Integer in fromRational $ s1 % picoSec+
src/Data/Time/Hora/Type/Time.hs view
@@ -1,14 +1,79 @@-module Data.Time.Hora.Type.Time where+module Data.Time.Hora.Type.Time + (Tz(..),+ TwoInt(..),+ TimeSpan(..)) where import Data.Time.LocalTime +data Tz a = Tz TimeZone a deriving (Show,Functor)+++-- | various precision data TimeSpan a = Sec a | Pico a- | Milli a deriving (Show, Eq, Ord)+ | Milli a deriving (Show, Functor) -data Tz a = Tz TimeZone a deriving (Show,Functor)- -- | constraint type TwoInt a b = (Integral a, Integral b)+++++-- | ! fromInteger returns 'Pico'. assumes the value is Pico seconds+instance Integral a => Num (TimeSpan a) where+ (+) = withPico (+)+ (*) = withPico (*)+ abs a0 = if a0 > Pico 0 then a0 else - a0+ signum a0+ | a0 > Pico 0 = 1+ | a0 < Pico 0 = - 1+ | otherwise = 0+ fromInteger i0 = Pico $ fromIntegral i0+ (-) = withPico (-)+++-- | safe to mix sec \/ pico \/ milli +instance (Eq a, Integral a) => Eq (TimeSpan a) where+ (==) (Sec a0) (Sec b0) = a0 == b0+ (==) (Milli a0) (Milli b0) = a0 == b0+ (==) (Pico a0) (Pico b0) = a0 == b0+ (==) a0 b0 = a1 == b1+ where a1 = toPico a0::Integer+ b1 = toPico b0::Integer+++-- | safe to mix sec \/ pico \/ milli +instance (Ord a, Integral a) => Ord (TimeSpan a) where+ (<=) (Sec a0) (Sec b0) = a0 <= b0+ (<=) (Milli a0) (Milli b0) = a0 <= b0+ (<=) (Pico a0) (Pico b0) = a0 <= b0+ (<=) a0 b0 = a1 <= b1+ where a1 = toPico a0::Integer+ b1 = toPico b0::Integer+++withPico::Integral a => (a -> a -> a) ->+ TimeSpan a -> TimeSpan a -> TimeSpan a+withPico fn0 a0 b0 = Pico $ fn0 a1 b1+ where a1 = toPico a0+ b1 = toPico b0+++{- | >>> toPico (Milli 1) + 1000000000 -}+toPico::TwoInt a b => TimeSpan a -> b+toPico (Pico i0) = fromIntegral i0+toPico (Milli i0) = fromIntegral $ i0 * picoMs+toPico (Sec i0) = fromIntegral $ i0 * picoSec++++-- | pico in 1 second+picoSec::Integral a => a+picoSec = 1000000000000 -- 12++-- | pico in 1 milli+picoMs::Integral a => a+picoMs = 1000000000 -- 9
test/Test/TestConvert.hs view
@@ -23,6 +23,18 @@ toMilli (Sec $ i 17) `shouldBe` (toMilli $ Pico $ toPico $ Sec $ i 17) toMilli (Milli $ i 170) `shouldBe` (toMilli $ Pico $ toPico $ Milli $ i 170) s1 `shouldBe` i3+ describe "TimeSpan Num" $ do+ it "pico Num" $ do + Milli 1 + (Milli 2) `shouldBe` (Pico $ (picoMs * 1) + (picoMs * 2)) + Sec 2 - (Sec 1) `shouldBe` (Pico $ (picoSec * 2) - (picoSec * 1)) + Pico 2 * (Milli 10) `shouldBe` (Pico $ 2 * (picoMs * 10))+ describe "TimeSpan Ord" $ do+ it "pico Ord" $ do+ Milli 10 `shouldSatisfy` (< (Sec 1)) + Milli 10 `shouldSatisfy` (> (Milli 9)) + Pico 10 `shouldSatisfy` (< (Sec 1)) + Pico 10 `shouldSatisfy` (< (Milli 1)) + picoMs * 10 `shouldSatisfy` (== (toPico $ Milli 10)) where p1 = toPico (Sec i3)::Int m1 = toMilli (Pico p1)::Int s1 = toSec (Milli m1)::Int