Skip to content
/ tiempo Public

Specify time intervals in different units (secs, mins, hours, etc.)

License

Notifications You must be signed in to change notification settings

HaskVan/tiempo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiempo

A sane and simple API that sits on top of the time library; it allows the creation of time intervals, and functions to manipulate time using them. Inspired on the Time module found on distributed-process-platform.

Example:

import qualified Control.Concurrent as Concurrent (threadDelay)
import           Data.Time          (UTCTime, addUTCTime, getCurrentTime)
import           Tiempo             (TimeInterval, days, hours, minutes,
                                     seconds, toMicroSeconds, toNominalDiffTime,
                                     toSeconds)

threadDelay :: TimeInterval -> IO ()
threadDelay = Concurrent.threadDelay . toMicroSeconds

fromTime :: TimeInterval ->  UTCTime -> UTCTime
fromTime interval = addUTCTime (toNominalDiffTime interval)

fromNow :: TimeInterval -> IO UTCTime
fromNow interval = fromTime interval `fmap` getCurrentTime

agoTime :: TimeInterval -> UTCTime -> UTCTime
agoTime interval = addUTCTime (realToFrac (-1 * toSeconds interval))

ago :: TimeInterval -> IO UTCTime
ago interval = agoTime interval `fmap` getCurrentTime

main :: IO ()
main = do
  ago (minutes 3) >>= print
  getCurrentTime >>= print
  fromNow (minutes 3) >>= print
  fromNow (hours 4) >>= print
  fromNow (days 1) >>= print
  threadDelay $ seconds 5
  putStrLn "DONE"

About

Specify time intervals in different units (secs, mins, hours, etc.)

Resources

License

Stars

Watchers

Forks

Packages

No packages published