polysemy-chronos 0.2.0.3 → 0.3.0.0
raw patch · 3 files changed
+21/−81 lines, 3 filesdep +incipit-coredep −polysemysetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies added: incipit-core
Dependencies removed: polysemy
API changes (from Hackage documentation)
Files
- Setup.hs +2/−0
- polysemy-chronos.cabal +4/−12
- readme.md +15/−69
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
polysemy-chronos.cabal view
@@ -1,11 +1,11 @@ cabal-version: 2.2 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.34.6. -- -- see: https://github.com/sol/hpack name: polysemy-chronos-version: 0.2.0.3+version: 0.3.0.0 synopsis: Polysemy-time Interpreters for Chronos description: Please see the readme on Github at <https://github.com/tek/polysemy-time> category: Time@@ -24,10 +24,6 @@ Polysemy.Chronos Polysemy.Chronos.Orphans Polysemy.Chronos.Time- other-modules:- Paths_polysemy_chronos- autogen-modules:- Paths_polysemy_chronos hs-source-dirs: lib default-extensions:@@ -92,12 +88,10 @@ build-depends: base ==4.* , chronos >=1.1.1 && <1.2- , polysemy >=1.4+ , incipit-core >=0.1 , polysemy-time mixins: base hiding (Prelude)- , polysemy-time hiding (Polysemy.Time.Prelude)- , polysemy-time (Polysemy.Time.Prelude as Prelude) default-language: Haskell2010 test-suite polysemy-chronos-unit@@ -105,7 +99,6 @@ main-is: Main.hs other-modules: Polysemy.Chronos.ChronosTimeTest- Paths_polysemy_chronos hs-source-dirs: test default-extensions:@@ -170,12 +163,11 @@ build-depends: base ==4.* , chronos+ , incipit-core , polysemy-chronos , polysemy-test , polysemy-time , tasty mixins: base hiding (Prelude)- , polysemy-time hiding (Polysemy.Time.Prelude)- , polysemy-time (Polysemy.Time.Prelude as Prelude) default-language: Haskell2010
readme.md view
@@ -1,89 +1,35 @@ # About -This Haskell library provides a [Polysemy] effect for accessing the current-time and date and an implementation for [time] and [chronos].+This Haskell library provides interpreters for the `Time` effect from [polysemy-time]. # Example ```haskell-import Data.Time (UTCTime) import Polysemy (Members, runM)-import Polysemy.Chronos (interpretTimeChronos)+import Polysemy.Chronos (ChronosTime, interpretTimeChronosConstantAt, interpretTimeChronos) import qualified Polysemy.Time as Time-import Polysemy.Time (MilliSeconds(MilliSeconds), Seconds(Seconds), Time, interpretTimeGhcAt, mkDatetime, year)+import Polysemy.Time (MilliSeconds(MilliSeconds), mkDatetime) +startTime :: Chronos.Time+startTime =+ Chronos.datetimeToTime (Time.mkDatetime 2020 01 01 0 0 0)+ prog :: Ord t =>- Member (Time t d) r =>- Sem r ()+ Members [ChronosTime, Embed IO] r =>+ Sem r Bool prog = do- time1 <- Time.now- Time.sleep (MilliSeconds 10)- time2 <- Time.now- print (time1 < time2)- -- True--testTime :: UTCTime-testTime =- mkDatetime 1845 12 31 23 59 59+ Time.sleep (MilliSeconds 1)+ time <- Time.now+ pure (time == startTime) main :: IO () main = runM do- interpretTimeChronos prog- interpretTimeGhcAt testTime do- Time.sleep (Seconds 1)- time <- Time.now- print (year time)- -- Years { unYear = 1846 }-```--# Effect--The only effect contained in **polysemy-time** is:--```haskell-data Time (time :: Type) (date :: Type) :: Effect where- Now :: Time t d m t- Today :: Time t d m d- Sleep :: TimeUnit u => u -> Time t d m ()- SetTime :: t -> Time t d m ()- SetDate :: d -> Time t d m ()-```--Interpreters are provided for the [time library](time) bundled with GHC and [chronos].--The type parameters correspond to the representations in the implementation,-like `Data.Time.UTCTime`/`Chronos.Time` and `Data.Time.Day`/`Chronos.Date`.--`SetTime` and `SetDate` only have meaning when you're running in a testing context.--A special interpreter variant suffixed with `At` exists for both-implementations, with which the current time is overridden to be relative to-the supplied override fixed at the start of interpretation.-This is useful for testing.--# Utilities--A set of newtypes representing timespans are provided for convenience.-Internally, the interpreters operate on `NanoSecond`s.--The class `TimeUnit` ties those types, and the types `Chronos.Timespan` and-`Data.Time.DiffTime`, together to allow you to convert between them with the-function `convert`:--```haskell->>> convert (picosecondsToDiffTime 50000000) :: MicroSeconds-MicroSeconds {unMicroSeconds = 50}-->>> convert (Days 5) :: Timespan-Timespan {getTimespan = 432000000000000}+ print =<< interpretTimeChronos prog -- False+ print =<< interpretTimeChronosConstantAt prog -- True ``` -The class `Calendar` allows you to construct `UTCTime` and `Chronos.Datetime`-from integers with the function `mkDatetime`, as demonstrated in the first-example.- [Polysemy]: https://hackage.haskell.org/package/polysemy-[time]: https://hackage.haskell.org/package/time+[polysemy-time]: https://hackage.haskell.org/package/polysemy-time [chronos]: https://hackage.haskell.org/package/chronos