packages feed

non-negative-time-diff 0.0.1 → 0.0.2

raw patch · 3 files changed

+35/−6 lines, 3 files

Files

changelog.md view
@@ -1,4 +1,7 @@ # non-negative-time-diff changelog +## Version 0.0.2 2026-03-12+  * support static build via -DSTATIC+ ## Version 0.0.1 2026-02-26   * init
non-negative-time-diff.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name:          non-negative-time-diff-version:       0.0.1+version:       0.0.2  synopsis:      type safe diffUTCTime description:@@ -94,6 +94,16 @@     <https://hackage.haskell.org/package/ghc-typelits-natnormalise natnormalise plugin>:          > {-# GHC_OPTIONS -fplugin GHC.TypeLits.Normalise #-}+    +    === Static linking+    #static-linking#+    +    In case of static linking define macro @STATIC@ to disable natnormalise+    GHC plugin that is not available in such setup. UtcBox version for the+    static build is less strict, because it does not have existential+    variable.+    +    > cabal build --ghc-option=-optP=-DSTATIC homepage:      http://github.com/yaitskov/non-negative-time-diff license:       BSD-3-Clause license-file:  LICENSE@@ -117,7 +127,7 @@  common base   default-language: GHC2024-  ghc-options: -Wall  -fplugin GHC.TypeLits.Normalise+  ghc-options: -Wall   default-extensions:     DefaultSignatures     NoImplicitPrelude
src/Data/Time/Clock/NonNegativeTimeDiff.hs view
@@ -1,3 +1,9 @@+{-# LANGUAGE CPP #-}+-- #define STATIC+#if !defined(STATIC)+{-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-}+#endif+ module Data.Time.Clock.NonNegativeTimeDiff   ( UtcBox   , UTCTime@@ -16,7 +22,7 @@ import Data.Coerce ( coerce ) import Data.Time.Clock qualified as C import Data.SafeCopy-    ( SafeCopy(putCopy, getCopy), contain, safeGet, safePut )+     ( SafeCopy(putCopy, getCopy), contain, safeGet, safePut ) import GHC.Conc ( STM, unsafeIOToSTM ) import GHC.Generics ( Generic ) import GHC.TypeLits ( TypeError, type (+), type (<=?), ErrorMessage(Text), Nat )@@ -24,19 +30,25 @@ import Prelude import System.Directory qualified as D -newtype UTCTime (n :: Nat)-  = UTCTime-  { unUTCTime :: C.UTCTime }+newtype UTCTime (n :: Nat) = UTCTime { unUTCTime :: C.UTCTime }   deriving newtype (Show, Eq, Ord, Generic, Read, NFData)  class Monad m => ClockMonad m where   getCurrentTime :: m (UTCTime 0)   getTimeAfter :: UTCTime n -> m (UTCTime (n + 1)) +#if !defined(STATIC) data UtcBox = forall n. UtcBox (UTCTime n)+#else+newtype UtcBox = UtcBox (UTCTime 0)+#endif  mkUtcBox :: UTCTime n -> UtcBox+#if defined(STATIC)+mkUtcBox (UTCTime ut) = UtcBox $ UTCTime ut+#else mkUtcBox = UtcBox+#endif  instance NFData UtcBox where   rnf (UtcBox u) = rnf u@@ -54,7 +66,11 @@   putCopy (UtcBox (UTCTime ut)) = contain $ safePut ut   getCopy= contain $ UtcBox . UTCTime <$> safeGet +#if defined(STATIC)+doAfter :: ClockMonad m => UtcBox -> (UTCTime 0 -> m b) -> m b+#else doAfter :: ClockMonad m => UtcBox -> (forall n. (UTCTime n -> m b)) -> m b+#endif doAfter (UtcBox u) m = m u  getModificationTime :: MonadIO m => FilePath -> m UtcBox