packages feed

timespan 0.2.0.0 → 0.3.0.0

raw patch · 2 files changed

+21/−6 lines, 2 files

Files

src/Data/Time/TimeSpan.hs view
@@ -1,10 +1,10 @@ {-# LANGUAGE BangPatterns #-} module Data.Time.TimeSpan   ( TimeSpan-  , milliseconds, seconds, minutes, hours, days-  , toMicroseconds, toMilliseconds, toSeconds, toMinutes, toHours, toDays-  , absTS-  , diffUTCTimeTS, addUTCTimeTS+  , milliseconds, seconds, minutes, hours, days, weeks+  , toMicroseconds, toMilliseconds, toSeconds, toMinutes, toHours, toDays, toWeeks+  , absTS, multiplyTS+  , diffUTCTimeTS, addUTCTimeTS, subUTCTimeTS   , sleepTS, timeoutTS   , timeAction   )@@ -16,11 +16,14 @@ import System.Timeout  -- | An abstract timespan. Use the provided smart constructors to create--- a meaningful timespan+-- a meaningful timespan. Note that on first sight a `Num` instance might+-- seem desirable, but this would defeat the purpose of having transparent+-- and explicitly constructed timespans due to `fromInteger`. newtype TimeSpan   = TimeSpan { unTimeSpan :: Double } -- as milliseconds   deriving (Show, Eq, Ord) +-- | An empty `TimeSpan` is 0, and `mappend` is defined as addition instance Monoid TimeSpan where     mempty = TimeSpan 0     mappend (TimeSpan a) (TimeSpan b) = TimeSpan (a + b)@@ -40,6 +43,9 @@ days :: Double -> TimeSpan days = hours . (* 24) +weeks :: Double -> TimeSpan+weeks = days . (* 7)+ toMicroseconds :: TimeSpan -> Double toMicroseconds = (* 1000) . toMilliseconds @@ -58,14 +64,23 @@ toDays :: TimeSpan -> Double toDays = (/24) . toHours +toWeeks :: TimeSpan -> Double+toWeeks = (/7) . toDays+ absTS :: TimeSpan -> TimeSpan absTS (TimeSpan x) = TimeSpan (abs x) +multiplyTS :: TimeSpan -> Double -> TimeSpan+multiplyTS (TimeSpan x) fact = TimeSpan (fact * x)+ diffUTCTimeTS :: UTCTime -> UTCTime -> TimeSpan diffUTCTimeTS a b = seconds $ fromRational $ toRational $ diffUTCTime a b  addUTCTimeTS :: TimeSpan -> UTCTime -> UTCTime addUTCTimeTS a = addUTCTime (fromRational $ toRational $ toSeconds a)++subUTCTimeTS :: TimeSpan -> UTCTime -> UTCTime+subUTCTimeTS a = addUTCTime ((-1) * fromRational (toRational $ toSeconds a))  sleepTS :: TimeSpan -> IO () sleepTS ts = threadDelay (round $ toMicroseconds ts)
timespan.cabal view
@@ -1,5 +1,5 @@ name:                timespan-version:             0.2.0.0+version:             0.3.0.0 synopsis:            Useful timespan datatype and functions description:         A data type for time spans with some useful utility functions homepage:            https://github.com/agrafix/timespan#readme