packages feed

text-builder 0.6 → 0.6.1

raw patch · 4 files changed

+39/−2 lines, 4 filesdep +transformers

Dependencies added: transformers

Files

library/Text/Builder.hs view
@@ -27,6 +27,7 @@   unsignedHexadecimal,   hexadecimalDigit,   padFromLeft,+  intervalInSeconds, ) where @@ -248,3 +249,20 @@   in if paddedLength <= builderLength     then builder     else foldMap char (replicate (paddedLength - builderLength) paddingChar) <> builder++{-|+Time interval in seconds.+Directly applicable to 'DiffTime' and 'NominalDiffTime'.+-}+{-# INLINABLE intervalInSeconds #-}+intervalInSeconds :: RealFrac seconds => seconds -> Builder+intervalInSeconds interval = flip evalState (round interval) $ do+  seconds <- state (swap . flip divMod 60)+  minutes <- state (swap . flip divMod 60)+  hours <- state (swap . flip divMod 24)+  days <- get+  return $+    padFromLeft 2 '0' (decimal days) <> ":" <>+    padFromLeft 2 '0' (decimal hours) <> ":" <>+    padFromLeft 2 '0' (decimal minutes) <> ":" <>+    padFromLeft 2 '0' (decimal seconds)
library/Text/Builder/Prelude.hs view
@@ -85,4 +85,13 @@ ------------------------- import DeferredFolds.Unfoldr as Exports (Unfoldr(..)) +-- transformers+-------------------------+import Control.Monad.IO.Class as Exports+import Control.Monad.Trans.Class as Exports+import Control.Monad.Trans.Maybe as Exports hiding (liftListen, liftPass)+import Control.Monad.Trans.Reader as Exports hiding (liftCallCC, liftCatch)+import Control.Monad.Trans.State.Strict as Exports hiding (liftCallCC, liftCatch, liftListen, liftPass)++ data Product2 a b = Product2 !a !b
test/Main.hs view
@@ -75,4 +75,13 @@     ,     testCase "Negative Hexadecimal" $     assertEqual "" "-1f23" (B.run (B.hexadecimal (-0x01f23)))+    ,+    testGroup "Time interval" $+    [+      testCase "59s" $ assertEqual "" "00:00:00:59" $ B.run $ B.intervalInSeconds 59,+      testCase "minute" $ assertEqual "" "00:00:01:00" $ B.run $ B.intervalInSeconds 60,+      testCase "90s" $ assertEqual "" "00:00:01:30" $ B.run $ B.intervalInSeconds 90,+      testCase "hour" $ assertEqual "" "00:01:00:00" $ B.run $ B.intervalInSeconds 3600,+      testCase "day" $ assertEqual "" "01:00:00:00" $ B.run $ B.intervalInSeconds 86400+    ]   ]
text-builder.cabal view
@@ -1,5 +1,5 @@ name: text-builder-version: 0.6+version: 0.6.1 category: Text synopsis: An efficient strict text builder homepage: https://github.com/nikita-volkov/text-builder@@ -27,7 +27,8 @@     bytestring >=0.10 && <0.11,     deferred-folds >=0.8 && <0.9,     semigroups >=0.18 && <0.19,-    text >=1 && <2+    text >=1 && <2,+    transformers >=0.5 && <0.6  test-suite test   type: exitcode-stdio-1.0