o-clock 1.3.0 → 1.4.0
raw patch · 4 files changed
+39/−52 lines, 4 filesdep ~aesondep ~doctestdep ~hedgehogPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, doctest, hedgehog, markdown-unlit, tasty
API changes (from Hackage documentation)
- Time.Units: toNum :: forall (unitTo :: Rat) n (unit :: Rat). (KnownDivRat unit unitTo, Num n) => Time unit -> n
+ Time.Units: instance Data.Typeable.Internal.Typeable rat => Data.Data.Data (Time.Units.Time rat)
Files
- CHANGELOG.md +8/−1
- o-clock.cabal +11/−12
- src/Time/Rational.hs +17/−2
- src/Time/Units.hs +3/−37
CHANGELOG.md view
@@ -9,8 +9,15 @@ o'clock uses [PVP Versioning][1]. The change log is available [on GitHub][2]. -Unreleased+1.4.0 =====++* [#136](https://github.com/serokell/o-clock/pull/136)+ + Remove `toNum`.+* [#139](https://github.com/serokell/o-clock/pull/139)+ + Add `Data` instance to `Time`.+* [#140](https://github.com/serokell/o-clock/pull/140)+ + Increase some upper bounds. 1.3.0 =====
o-clock.cabal view
@@ -4,7 +4,7 @@ -- SPDX-License-Identifier: MPL-2.0 name: o-clock-version: 1.3.0+version: 1.4.0 synopsis: Type-safe time library. description: See README.md for details. homepage: https://github.com/serokell/o-clock@@ -20,11 +20,10 @@ extra-doc-files: CHANGELOG.md , README.md , README.lhs-tested-with: GHC == 8.6.5- , GHC == 8.8.3- , GHC == 8.10.4- , GHC == 9.0.2- , GHC == 9.2.4+tested-with: GHC == 9.0.2+ , GHC == 9.2.8+ , GHC == 9.4.5+ , GHC == 9.6.2 source-repository head type: git@@ -50,7 +49,7 @@ TypeApplications TypeFamilies if flag(aeson)- build-depends: aeson >= 1.2.4 && < 2.1+ build-depends: aeson >= 1.2.4 && < 2.3 , text cpp-options: -DHAS_aeson @@ -74,10 +73,10 @@ Test.Time.Units build-depends: o-clock- , hedgehog >= 0.6 && < 1.3+ , hedgehog >= 0.6 && < 1.4 , hspec-expectations ^>= 0.8- , tasty >= 0.12 && < 1.5- , tasty-hedgehog >= 0.1 && < 1.3.2+ , tasty >= 0.12 && < 1.6+ , tasty-hedgehog >= 0.1 && < 1.5.0 , tasty-hunit-compat ^>= 0.2 , type-spec >= 0.3.0.1 && < 0.5 @@ -95,7 +94,7 @@ main-is: Doctest.hs build-tool-depends: doctest:doctest- build-depends: doctest >= 0.16 && < 0.21+ build-depends: doctest >= 0.16 && < 0.23 , Glob >= 0.9 && < 0.11 ghc-options: -threaded -rtsopts -with-rtsopts=-N @@ -109,7 +108,7 @@ build-tool-depends: markdown-unlit:markdown-unlit build-depends: o-clock- , markdown-unlit ^>= 0.5+ , markdown-unlit >= 0.5 && < 0.7 ghc-options: -threaded -rtsopts -with-rtsopts=-N -pgmL markdown-unlit benchmark o-clock-benchmark
src/Time/Rational.hs view
@@ -1,18 +1,28 @@--- SPDX-FileCopyrightText: 2019 Serokell <https://serokell.io>+-- SPDX-FileCopyrightText: 2019-2023 Serokell <https://serokell.io> -- -- SPDX-License-Identifier: MPL-2.0 {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE NoStarIsType #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE Rank2Types #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} +-- See https://github.com/ghc/ghc/commit/13d627bbd0bc3dd30d672de341aa7f471be0aa2c+-- Starting from 9.6, GHC doesn't print promotion ticks when they are not necessary.+-- Because of that we need to support too many cases in doctests.+-- Let's force redundant ticks for now and remove this flag later when we stop+-- supporting 9.0 at least.+#if ( __GLASGOW_HASKELL__ >= 906 )+{-# OPTIONS_GHC -fprint-redundant-promotion-ticks #-}+#endif+ -- | This module introduces 'Rat' kind and all necessary functional. module Time.Rational@@ -43,6 +53,11 @@ import GHC.TypeNats (Div, KnownNat, Mod, Nat, natVal, type (<=?)) import qualified GHC.TypeNats import Unsafe.Coerce (unsafeCoerce)++#if ( __GLASGOW_HASKELL__ >= 906 )+-- $setup+-- >>> {-# OPTIONS_GHC -fprint-redundant-promotion-ticks #-}+#endif -- | Data structure represents the rational number. -- Rational number can be represented as a pair of
src/Time/Units.hs view
@@ -6,6 +6,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE ExplicitForAll #-} {-# LANGUAGE FlexibleContexts #-}@@ -45,7 +46,6 @@ , floorRat , ceilingUnit , ceilingRat- , toNum , toFractional , sec@@ -71,6 +71,7 @@ import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Char (isDigit, isLetter) import Data.Coerce (coerce)+import Data.Data (Data) import Data.Foldable (foldl') import Data.Proxy (Proxy (..)) import Data.Semigroup (Semigroup (..))@@ -116,7 +117,7 @@ -- | Time unit is represented as type level rational multiplier with kind 'Rat'. newtype Time (rat :: Rat) = Time { unTime :: RatioNat }- deriving (Eq, Ord, Enum, Generic)+ deriving (Eq, Ord, Enum, Generic, Data) -- | Addition is associative binary operation for 'Semigroup' of 'Time'. instance Semigroup (Time (rat :: Rat)) where@@ -342,41 +343,6 @@ -} ceilingUnit :: forall (unit :: Rat) . Time unit -> Time unit ceilingUnit = time . fromIntegral @Natural . ceilingRat--{- | Convert time to the 'Num' in given units.--For example, instead of writing--@-foo :: POSIXTime-foo = 10800 -- 3 hours-@--one can write more safe implementation:--@-foo = toNum @Second $ hour 3-@--__Examples:__-->>> toNum @Second @Natural $ hour 3-10800-->>> toNum @Minute @Int $ hour 3-180-->>> toNum @Hour @Natural $ hour 3-3---}-toNum :: forall (unitTo :: Rat) n (unit :: Rat) . (KnownDivRat unit unitTo, Num n)- => Time unit -> n-toNum = fromIntegral @Natural . floorRat . toUnit @unitTo-{-# DEPRECATED toNum- [ "May lead to unexpected flooring of the fractional time."- , "Use 'toFractional' to avoid rounding or 'floorRat' to keep the flooring behaviour."- ] #-} {- | Convert the 'Time' object to the 'Fractional' value.