duration: A tiny compile-time time utility library inspired by zeit/ms

[ bsd3, library, time ] [ Propose Tags ]

A tiny compile-time time utility library inspired by zeit/ms


[Skip to Readme]
Versions [faq] 0.1.0.0
Dependencies base (>=4.7 && <5), parsec, template-haskell, time [details]
License BSD-3-Clause
Copyright 2018 Ryota Kameoka
Author Ryota Kameoka
Maintainer kameoka.ryota@gmail.com
Category Time
Home page https://github.com/ryota-ka/duration#readme
Bug tracker https://github.com/ryota-ka/duration/issues
Source repo head: git clone https://github.com/ryota-ka/duration
Uploaded by ryotakameoka at Fri Apr 27 15:53:16 UTC 2018
Distributions LTSHaskell:0.1.0.0, NixOS:0.1.0.0, Stackage:0.1.0.0
Downloads 319 total (13 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2018-04-28 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for duration-0.1.0.0

[back to package description]

duration

A tiny compile-time time utility library, inspired by zeit/ms.

Examples

{-# 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 |]   -- -60s

    print @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.000000000001s

    print @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