Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryota-ka/duration
A tiny compile-time time utility library, inspired by zeit/ms.
https://github.com/ryota-ka/duration
haskell template-haskell time
Last synced: 22 days ago
JSON representation
A tiny compile-time time utility library, inspired by zeit/ms.
- Host: GitHub
- URL: https://github.com/ryota-ka/duration
- Owner: ryota-ka
- License: bsd-3-clause
- Created: 2018-02-15T19:51:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-13T06:41:36.000Z (over 3 years ago)
- Last Synced: 2024-10-05T02:35:28.255Z (about 1 month ago)
- Topics: haskell, template-haskell, time
- Language: Haskell
- Homepage: https://hackage.haskell.org/package/duration
- Size: 14.6 KB
- Stars: 9
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# duration
A tiny compile-time time utility library, inspired by [zeit/ms](https://github.com/zeit/ms).
## Examples
```haskell
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TypeApplications #-}module Main where
import Data.Time.Clock (DiffTime, NominalDiffTime)
import Data.Time.Clock.Duration (t, s, ms, µs, ns, ps)main :: IO ()
main = do
print @DiffTime [t| 1 day |] -- 86400s
print @DiffTime [t| 2h |] -- 7200s
print @DiffTime [t| -1m |] -- -60sprint @NominalDiffTime [s| 1 |] -- 1s
print @NominalDiffTime [ms| 1 |] -- 0.001s
print @NominalDiffTime [µs| 1 |] -- 0.000001s
print @NominalDiffTime [ns| 1 |] -- 0.000000001s
print @NominalDiffTime [ps| 1 |] -- 0.000000000001sprint @Int [s| 2 days |] -- 172800
print @Integer [ms| 5s |] -- 5000
print @Double [µs| 2min |] -- 1.2e8
print @Float [ns| -1 sec |] -- -1.0e9
print @Rational [ps| 10ms |] -- 10000000000 % 1
```