packages feed

o-clock 0.1.0 → 0.1.1

raw patch · 6 files changed

+61/−15 lines, 6 filesdep −transformersdep ~basesetup-changedPVP ok

version bump matches the API change (PVP)

Dependencies removed: transformers

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Time.Units: instance Data.Semigroup.Semigroup (Time.Units.Time rat)
+ Time.Units: instance GHC.Base.Monoid (Time.Units.Time rat)

Files

CHANGELOG.md view
@@ -3,6 +3,21 @@ o'clock uses [PVP Versioning][1]. The change log is available [on GitHub][2]. +1.0.0+=====++* TODO++0.1.1+=====++* [#98](https://github.com/serokell/o-clock/issues/98):+  Support GHC-8.0.2.+* [#95](https://github.com/serokell/o-clock/issues/95):+  Add `Semigroup` and `Monoid` instances for `Time`.+* [#93](https://github.com/serokell/o-clock/issues/93):+  Remove `transformers` dependency.+ 0.1.0 ===== 
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
o-clock.cabal view
@@ -1,5 +1,5 @@ name:                o-clock-version:             0.1.0+version:             0.1.1 synopsis:            Type-safe time library. description:         See README.md for details. homepage:            https://github.com/serokell/o-clock@@ -15,7 +15,9 @@                    , README.md                    , README.lhs cabal-version:       >=2.0-tested-with:         GHC == 8.4.1+tested-with:         GHC == 8.0.2+                   , GHC == 8.2.2+                   , GHC == 8.4.1  source-repository head   type:     git@@ -29,9 +31,8 @@                          Time.Timestamp                          Time.Units   ghc-options:         -Wall-  build-depends:       base         >= 4.10  && < 5+  build-depends:       base         >= 4.9  && < 5                      , ghc-prim     >= 0.5-                     , transformers >= 0.5   default-language:    Haskell2010   default-extensions:  OverloadedStrings                        RecordWildCards@@ -42,7 +43,7 @@ executable play-o-clock   main-is:             Playground.hs   build-depends:       o-clock-                     , base     >= 4.10  && < 5+                     , base     >= 4.9  && < 5   hs-source-dirs:      examples   default-language:    Haskell2010   ghc-options:         -threaded -Wall@@ -58,7 +59,7 @@                        Test.Time.TypeSpec                        Test.Time.Units -  build-depends:       base            >= 4.10  && < 5+  build-depends:       base            >= 4.9  && < 5                      , o-clock                      , hedgehog       ^>= 0.5.1                      , tasty          ^>= 0.12
src/Time/Rational.hs view
@@ -41,10 +41,17 @@ import Data.Proxy (Proxy (..)) import GHC.Natural (Natural) import GHC.Real (Ratio ((:%)))+ #if ( __GLASGOW_HASKELL__ >= 804 ) import GHC.TypeNats (Div, Mod, type (<=?)) #endif++#if ( __GLASGOW_HASKELL__ >= 802 ) import GHC.TypeNats (KnownNat, Nat, natVal)+#else+import GHC.TypeLits (KnownNat, Nat, natVal)+#endif+ #if ( __GLASGOW_HASKELL__ >= 804 ) import Unsafe.Coerce (unsafeCoerce) #endif@@ -213,8 +220,11 @@     ratVal :: RatioNat  instance (KnownNat a, KnownNat b) => KnownRat (a :% b) where+#if ( __GLASGOW_HASKELL__ >= 802 )     ratVal = natVal (Proxy @a) :% natVal (Proxy @b)-+#else+    ratVal = fromIntegral (natVal (Proxy @a)) :% fromIntegral (natVal (Proxy @b))+#endif  #if ( __GLASGOW_HASKELL__ >= 804 ) newtype KnownRatDict (unit :: Rat) r = MkKnownRatDict (KnownRat unit => r)
src/Time/Timestamp.hs view
@@ -59,7 +59,7 @@          -> (Ordering, Time unit) timeDiff (Timestamp a) (Timestamp b) =     let (order, r) = ratDiff a b-    in (order, toUnit $ sec $ fromRational r)+    in (order, toUnit $ sec r)  {- | Returns the result of addition of 'Time' with 'Timestamp' elements. @@ -134,7 +134,8 @@ t1 +:+ t2 = toUnit t1 + t2 {-# INLINE (+:+) #-} --- | Substracts times of different units.+-- | Substracts time amounts of different units. When the minuend is smaller+-- than the subtrahend, this function will throw @Underflow :: ArithException@. -- -- >>> minute 1 -:- sec 1 -- 59s@@ -147,7 +148,9 @@ t1 -:- t2 = toUnit t1 - t2 {-# INLINE (-:-) #-} -{- | Similar to '-:-' but more safe and returns order in pair with resulting time difference.+{- | Compute the difference between two amounts of time. The result is returned+in two components: the ordering (which input is larger) and the numeric+difference (how much larger). Unlike '-:-', does not throw @ArithException@.  >>> sec 5 -%- sec 3 (GT,2s)@@ -164,12 +167,12 @@ t1 -%- (Time t2Rat) =     let (Time t1Rat) = toUnit @unitResult t1         (order, rat) = ratDiff (toRational t1Rat) (toRational t2Rat)-    in (order, Time $ fromRational rat)+    in (order, Time rat) -ratDiff :: Rational -> Rational -> (Ordering, Rational)+ratDiff :: Rational -> Rational -> (Ordering, RatioNat) ratDiff r1 r2 =     let order = compare r1 r2-        diff  = case order of+        diff  = fromRational $ case order of                      LT -> r2 - r1                      GT -> r1 - r2                      EQ -> 0
src/Time/Units.hs view
@@ -62,7 +62,9 @@ import Control.Monad (unless) import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Char (isDigit, isLetter)+import Data.Foldable (foldl') import Data.Proxy (Proxy (..))+import Data.Semigroup (Semigroup (..)) import GHC.Generics (Generic) import GHC.Natural (Natural) import GHC.Prim (coerce)@@ -119,6 +121,23 @@ -- | Time unit is represented as type level rational multiplier with kind 'Rat'. newtype Time (rat :: Rat) = Time { unTime :: RatioNat }     deriving (Eq, Ord, Enum, Real, RealFrac, Generic)++-- | Addition is associative binary operation for 'Semigroup' of 'Time'.+instance Semigroup (Time (rat :: Rat)) where+    (<>) = (+)+    {-# INLINE (<>) #-}+    sconcat = foldl' (<>) mempty+    {-# INLINE sconcat #-}+    stimes n (Time t) = Time (fromIntegral n * t)+    {-# INLINE stimes #-}++instance Monoid (Time (rat :: Rat)) where+    mempty  = Time 0+    {-# INLINE mempty #-}+    mappend = (<>)+    {-# INLINE mappend #-}+    mconcat = foldl' (<>) mempty+    {-# INLINE mconcat #-}  -- | Type family for prettier 'show' of time units. type family UnitName (unit :: Rat) :: Symbol