o-clock 1.0.0.1 → 1.1.0
raw patch · 9 files changed
+40/−135 lines, 9 filesdep ~Globdep ~hashabledep ~hedgehognew-uploaderPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: Glob, hashable, hedgehog, serialise, tasty, tasty-hedgehog, type-spec
API changes (from Hackage documentation)
- Time.Rational: type :% = '(::%)
+ Time.Rational: infix 4 >=%
+ Time.Rational: infixl 7 %
+ Time.Rational: type (:%) = '(::%)
+ Time.Rational: type family (m :: Rat) >=% (n :: Rat) :: Bool
+ Time.Series: type family (from :: Rat) ... (to :: Rat) :: [Rat]
+ Time.Units: type family UnitName (unit :: Rat) :: Symbol
- Time.Units: floorRat :: forall (unit :: Rat) b. (Integral b) => Time unit -> b
+ Time.Units: floorRat :: forall (unit :: Rat) b. Integral b => Time unit -> b
- Time.Units: unitNameVal :: forall (unit :: Rat). (KnownUnitName unit) => String
+ Time.Units: unitNameVal :: forall (unit :: Rat). KnownUnitName unit => String
Files
- CHANGELOG.md +10/−0
- README.lhs +0/−10
- README.md +0/−10
- o-clock.cabal +19/−11
- src/Time/Rational.hs +2/−35
- src/Time/Series.hs +5/−31
- src/Time/Units.hs +1/−23
- test/Test/Time/Property.hs +0/−4
- test/Test/Time/TypeSpec.hs +3/−11
CHANGELOG.md view
@@ -3,6 +3,16 @@ o'clock uses [PVP Versioning][1]. The change log is available [on GitHub][2]. +1.1.0+=====++* [#110](https://github.com/serokell/o-clock/issues/110):+ Resurrect `o-clock` in nightly resolver. Specifically:+ + Explicitly support GHC-8.8.+ + Bump many upper bounds.+ + Make benchmarks not buildable by default.+ + Drop support for GHC-8.0 and GHC-8.2.+ 1.0.0.1 =======
README.lhs view
@@ -85,9 +85,7 @@ module Main where -#if ( __GLASGOW_HASKELL__ >= 804 ) import Time (type (*))-#endif import Time ((:%), (-:-), Time, Hour, UnitName,floorUnit, hour, seriesF, toUnit) ```@@ -99,18 +97,10 @@ ```haskell -- | Time unit for a working day (8 hours).-#if ( __GLASGOW_HASKELL__ >= 804 ) type WorkDay = 8 * Hour-#else-type WorkDay = 28800 :% 1-#endif -- | Time unit for a work week (5 working days).-#if ( __GLASGOW_HASKELL__ >= 804 ) type WorkWeek = 5 * WorkDay-#else-type WorkWeek = 144000 :% 1-#endif -- this allows to use 'Show' and 'Read' functions for our time units type instance UnitName (28800 :% 1) = "wd" -- One WorkDay contains 28800 seconds
README.md view
@@ -85,9 +85,7 @@ module Main where -#if ( __GLASGOW_HASKELL__ >= 804 ) import Time (type (*))-#endif import Time ((:%), (-:-), Time, Hour, UnitName,floorUnit, hour, seriesF, toUnit) ```@@ -99,18 +97,10 @@ ```haskell -- | Time unit for a working day (8 hours).-#if ( __GLASGOW_HASKELL__ >= 804 ) type WorkDay = 8 * Hour-#else-type WorkDay = 28800 :% 1-#endif -- | Time unit for a work week (5 working days).-#if ( __GLASGOW_HASKELL__ >= 804 ) type WorkWeek = 5 * WorkDay-#else-type WorkWeek = 144000 :% 1-#endif -- this allows to use 'Show' and 'Read' functions for our time units type instance UnitName (28800 :% 1) = "wd" -- One WorkDay contains 28800 seconds
o-clock.cabal view
@@ -1,5 +1,5 @@ name: o-clock-version: 1.0.0.1+version: 1.1.0 synopsis: Type-safe time library. description: See README.md for details. homepage: https://github.com/serokell/o-clock@@ -16,10 +16,11 @@ , README.md , README.lhs cabal-version: 2.0-tested-with: GHC == 8.0.2- , GHC == 8.2.2- , GHC == 8.4.3+tested-with: GHC == 8.4.3+ , GHC == 8.4.4 , GHC == 8.6.1+ , GHC == 8.6.5+ , GHC == 8.8.1 source-repository head type: git@@ -46,13 +47,13 @@ , text cpp-options: -DHAS_aeson if flag(hashable)- build-depends: hashable >= 1.2.6 && < 1.3+ build-depends: hashable >= 1.2.6 && < 1.4 cpp-options: -DHAS_hashable if flag(deepseq) build-depends: deepseq ^>= 1.4 cpp-options: -DHAS_deepseq if flag(serialise)- build-depends: serialise >= 0.2+ build-depends: serialise >= 0.2 && < 0.3 cpp-options: -DHAS_serialise executable play-o-clock@@ -76,11 +77,11 @@ build-depends: base >= 4.9 && < 5 , o-clock- , hedgehog ^>= 0.6- , tasty >= 0.12 && < 1.2- , tasty-hedgehog >= 0.1 && < 0.3+ , hedgehog >= 0.6 && < 1.1+ , tasty >= 0.12 && < 1.3+ , tasty-hedgehog >= 0.1 && < 1.1 , tasty-hspec ^>= 1.1.3- , type-spec ^>= 0.3.0.1+ , type-spec >= 0.3.0.1 && < 0.5 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010@@ -95,7 +96,7 @@ build-tool-depends: doctest:doctest build-depends: base >= 4.10 && < 5 , doctest ^>= 0.16- , Glob ^>= 0.9+ , Glob >= 0.9 && < 0.11 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 @@ -125,6 +126,9 @@ build-depends: deepseq >= 1.4 cpp-options: -DNO_deepseq + if !flag(bench-buildable)+ buildable: False+ default-extensions: OverloadedStrings RecordWildCards @@ -144,4 +148,8 @@ flag serialise description: Provide instances for @serialise@+ default: False++flag bench-buildable+ description: Make benchmarks buildable default: False
src/Time/Rational.hs view
@@ -16,27 +16,21 @@ module Time.Rational ( Rat (..) , type (:%)-#if ( __GLASGOW_HASKELL__ >= 804 ) , type (%) , type (*) , type (/)-#endif , MulK , DivK-#if ( __GLASGOW_HASKELL__ >= 804 ) , Gcd , Normalize , DivRat , type (>=%)-#endif -- Utilities , RatioNat , KnownRat (..) -#if ( __GLASGOW_HASKELL__ >= 804 ) , withRuntimeDivRat-#endif , KnownDivRat ) where @@ -44,24 +38,9 @@ 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--#if ( __GLASGOW_HASKELL__ >= 804 )+import GHC.TypeNats (Div, Mod, type (<=?), KnownNat, Nat, natVal) import qualified GHC.TypeNats-#endif+import Unsafe.Coerce (unsafeCoerce) -- | Data structure represents the rational number. -- Rational number can be represented as a pair of@@ -85,7 +64,6 @@ type instance DivK Rat Nat = Rat type instance DivK Nat Rat = Rat -#if ( __GLASGOW_HASKELL__ >= 804 ) -- | Overloaded multiplication. type family (*) (a :: k1) (b :: k2) :: MulK k1 k2 @@ -101,12 +79,10 @@ type instance (a :: Rat) / (b :: Rat) = DivRat a b type instance (a :: Rat) / (b :: Nat) = DivRatNat a b type instance (a :: Nat) / (b :: Rat) = DivRat (a :% 1) b-#endif -- | More convenient name for promoted constructor of 'Rat'. type (:%) = '(::%) -#if ( __GLASGOW_HASKELL__ >= 804 ) -- | Type family for normalized pair of 'Nat's — 'Rat'. type family (m :: Nat) % (n :: Nat) :: Rat where a % b = Normalize (a :% b)@@ -213,7 +189,6 @@ type family (m :: Rat) >=% (n :: Rat) :: Bool where (a :% b) >=% (c :% d) = c * b <=? a * d -#endif -- | Rational numbers, with numerator and denominator of 'Natural' type. type RatioNat = Ratio Natural@@ -223,13 +198,8 @@ 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) giftRat :: forall (unit :: Rat) r . (KnownRat unit => r) -> RatioNat -> r@@ -240,12 +210,9 @@ withRuntimeDivRat :: forall (a :: Rat) (b :: Rat) r . (KnownRat a, KnownRat b) => (KnownRat (a / b) => r) -> r withRuntimeDivRat r = giftRat @(a / b) r (ratVal @a / ratVal @b) {-# INLINE withRuntimeDivRat #-}-#endif -- | Constraint alias for 'DivRat' units. type KnownDivRat a b = ( KnownRat a , KnownRat b-#if ( __GLASGOW_HASKELL__ >= 804 ) , KnownRat (a / b)-#endif )
src/Time/Series.hs view
@@ -12,9 +12,7 @@ module Time.Series ( AllTimes-#if ( __GLASGOW_HASKELL__ >= 804 ) , type (...)-#endif -- * Formatting , SeriesF (..) , unitsF@@ -25,20 +23,18 @@ ) where import Data.Char (isDigit, isLetter)-import Data.Semigroup ((<>))-import Text.Read (readMaybe)-#if ( __GLASGOW_HASKELL__ >= 804 ) import Data.Kind (Constraint)+import Data.Semigroup ((<>)) import Data.Type.Bool (type (&&), If) import Data.Type.Equality (type (==))-import GHC.TypeLits (TypeError, ErrorMessage (Text))+import GHC.TypeLits (ErrorMessage (Text), TypeError)+import Text.Read (readMaybe) import Time.Rational (type (>=%), withRuntimeDivRat)-#endif import Time.Rational (Rat)+import Time.Timestamp ((-:-)) import Time.Units (Day, Fortnight, Hour, KnownRatName, Microsecond, Millisecond, Minute, Nanosecond, Picosecond, Second, Time (..), Week, floorUnit, toUnit)-import Time.Timestamp ((-:-)) -- $setup -- >>> import Time.Units (Time (..), fortnight, hour, minute, ms, sec)@@ -53,7 +49,6 @@ , Millisecond , Microsecond, Nanosecond, Picosecond ] -#if ( __GLASGOW_HASKELL__ >= 804 ) {- | Creates the list of time units in descending order by provided the highest and the lowest bound of the desired list. Throws the error when time units are not in the right order.@@ -90,7 +85,6 @@ type family DescendingConstraint (b :: Bool) :: Constraint where DescendingConstraint 'True = () -- empty constraint; always satisfiable DescendingConstraint 'False = TypeError ('Text "List of units should be in descending order")-#endif {- | Class for time formatting. @@ -117,7 +111,6 @@ The received list should be in descending order. It would be verified at compile-time. Example of the error from @ghci@: -#if ( __GLASGOW_HASKELL__ >= 804 ) >>> seriesF @'[Millisecond, Second] (minute 42) ... • List of units should be in descending order@@ -125,7 +118,6 @@ In an equation for ‘it’: it = seriesF @'[Millisecond, Second] (minute 42) ...-#endif -} class SeriesF (units :: [Rat]) where@@ -141,37 +133,23 @@ seriesF :: forall (someUnit :: Rat) . KnownRatName someUnit => Time someUnit -> String seriesF t =-#if ( __GLASGOW_HASKELL__ >= 804 ) let newTime = withRuntimeDivRat @someUnit @unit $ toUnit @unit t-#else- let newTime = toUnit @unit t-#endif in show newTime instance ( KnownRatName unit , SeriesF (nextUnit : units)-#if ( __GLASGOW_HASKELL__ >= 804 ) , DescendingConstraint (IsDescending (unit ': nextUnit ': units))-#endif ) => SeriesF (unit ': nextUnit ': units :: [Rat]) where seriesF :: forall (someUnit :: Rat) . KnownRatName someUnit => Time someUnit -> String-#if ( __GLASGOW_HASKELL__ >= 804 ) seriesF t = let newUnit = withRuntimeDivRat @someUnit @unit $ toUnit @unit t-#else- seriesF t = let newUnit = toUnit @unit t-#endif flooredNewUnit = floorUnit newUnit timeStr = case flooredNewUnit of Time 0 -> ""- _ -> show flooredNewUnit+ _ -> show flooredNewUnit -#if ( __GLASGOW_HASKELL__ >= 804 ) nextUnit = withRuntimeDivRat @unit @unit $ newUnit -:- flooredNewUnit-#else- nextUnit = newUnit -:- flooredNewUnit-#endif in if nextUnit == Time 0 then show newUnit else timeStr ++ seriesF @(nextUnit ': units) @unit nextUnit@@ -239,9 +217,7 @@ instance ( KnownRatName unit , SeriesP (nextUnit : units)-#if ( __GLASGOW_HASKELL__ >= 804 ) , DescendingConstraint (IsDescending (unit ': nextUnit ': units))-#endif ) => SeriesP (unit ': nextUnit ': units :: [Rat]) where seriesP :: forall (someUnit :: Rat) . KnownRatName someUnit@@ -273,7 +249,5 @@ readMaybeTime :: forall (unit :: Rat) (someUnit :: Rat) . (KnownRatName unit, KnownRatName someUnit) => String -> Maybe (Time someUnit) readMaybeTime str =-#if ( __GLASGOW_HASKELL__ >= 804 ) withRuntimeDivRat @unit @someUnit $-#endif toUnit @someUnit <$> (readMaybe @(Time unit) str)
src/Time/Units.hs view
@@ -96,10 +96,7 @@ import qualified Data.Text as Text #endif -#if ( __GLASGOW_HASKELL__ >= 804 )-import Time.Rational (type (*), type (/))-#endif-import Time.Rational (type (:%), KnownDivRat, Rat, RatioNat, KnownRat, ratVal)+import Time.Rational (type (*), type (/), type (:%), KnownDivRat, Rat, RatioNat, KnownRat, ratVal) import qualified Control.Concurrent as Concurrent import qualified System.CPUTime as CPUTime@@ -109,7 +106,6 @@ -- Units ---------------------------------------------------------------------------- -#if ( __GLASGOW_HASKELL__ >= 804 ) type Second = 1 / 1 type Millisecond = Second / 1000 type Microsecond = Millisecond / 1000@@ -122,20 +118,6 @@ type Week = 7 * Day type Fortnight = 2 * Week -#else-type Second = 1 :% 1-type Millisecond = 1 :% 1000-type Microsecond = 1 :% 1000000-type Nanosecond = 1 :% 1000000000-type Picosecond = 1 :% 1000000000000--type Minute = 60 :% 1-type Hour = 3600 :% 1-type Day = 86400 :% 1-type Week = 604800 :% 1-type Fortnight = 1209600 :% 1-#endif- ---------------------------------------------------------------------------- -- Time data type ----------------------------------------------------------------------------@@ -415,11 +397,7 @@ toUnit :: forall (unitTo :: Rat) (unitFrom :: Rat) . KnownDivRat unitFrom unitTo => Time unitFrom -> Time unitTo-#if ( __GLASGOW_HASKELL__ >= 804 ) toUnit Time{..} = Time $ unTime * ratVal @(unitFrom / unitTo)-#else-toUnit (Time t) = Time (t * ratVal @unitFrom / ratVal @unitTo)-#endif {-# INLINE toUnit #-} {- | Convenient version of 'Control.Concurrent.threadDelay' which takes
test/Test/Time/Property.hs view
@@ -20,9 +20,7 @@ import Time (Day, Fortnight, Hour, KnownRat, KnownRatName, Microsecond, Millisecond, Minute, Nanosecond, Picosecond, Rat, RatioNat, Second, Time (..), Week, toUnit, unitsF, unitsP)-#if ( __GLASGOW_HASKELL__ >= 804 ) import Time (withRuntimeDivRat)-#endif import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range@@ -75,10 +73,8 @@ -> Time unitTo -> m () checkToUnit t _ =-#if ( __GLASGOW_HASKELL__ >= 804 ) withRuntimeDivRat @unitTo @unitFrom $ withRuntimeDivRat @unitFrom @unitTo $-#endif toUnit (toUnit @unitTo t) === t -- | Verifier for @ seriesP . seriesF @.
test/Test/Time/TypeSpec.hs view
@@ -10,25 +10,19 @@ import Test.TypeSpec import Test.TypeSpecCrazy -import Time.Rational ((:%))-#if ( __GLASGOW_HASKELL__ >= 804 )-import Time.Rational (type (/), type (>=%), Gcd, Normalize)-#endif-import Time.Units (Day, Fortnight, Hour, Microsecond, Millisecond, Minute,- Nanosecond, Picosecond, Second, UnitName, Week)+import Time.Rational (type (/), (:%), type (>=%), Gcd, Normalize)+import Time.Units (Day, Fortnight, Hour, Microsecond, Millisecond, Minute, Nanosecond, Picosecond,+ Second, UnitName, Week) runTypeSpecTests :: IO () runTypeSpecTests = do-#if ( __GLASGOW_HASKELL__ >= 804 ) print typeSpec_Gcd print typeSpec_Normalize print typeSpec_DivRat print typeSpec_Compare-#endif print typeSpec_UnitCalculation print typeSpec_UnitNames -#if ( __GLASGOW_HASKELL__ >= 804 ) typeSpec_Gcd :: "GCD"@@ -104,8 +98,6 @@ -*- It "5%42 >=% 1%42 = True" (((5 :% 42) >=% (1 :% 42)) `Is` 'True) typeSpec_Compare = Valid--#endif typeSpec_UnitCalculation ::