Copyright | (c) 2018 Christopher C Lord Pliosoft |
---|---|
License | BSD Style |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Maintainer : christopher@pliosoft.com Portability : GHC
Use a to contain some number of flicks, and provide standard numerical operations.
Based on idea from ChristopherHorvath
Synopsis
- data Duration
- flicksPerMillisecond :: Num a => a
- flicksPerSecond :: Num a => a
- flicksPerMinute :: Num a => a
- flickRatio :: Fractional a => a
- durationToRationalFlicks :: Duration -> Rational
- durationToRationalSeconds :: Duration -> Rational
- durationAsHours :: Duration -> Rational
- durationAsNanoseconds :: Duration -> Rational
- durationAsMicroseconds :: Duration -> Rational
- durationAsMilliseconds :: Duration -> Rational
- durationAsMinutes :: Duration -> Rational
- durationAsSeconds :: Duration -> Rational
- durationAsHms :: Duration -> (Integer, Integer, Integer, Integer, Integer)
- durationFromFlicks :: Integral a => a -> Duration
- durationFromHours :: Rational -> Duration
- durationFromNanoseconds :: Rational -> Duration
- durationFromMicroseconds :: Rational -> Duration
- durationFromMilliseconds :: Rational -> Duration
- durationFromMinutes :: Rational -> Duration
- durationFromSeconds :: Rational -> Duration
- durationOfOneBeatAtBPM :: Rational -> Maybe Duration
- durationOfOneCycleAtHz :: Rational -> Maybe Duration
- frequencyInHzForWavePeriod :: Duration -> Maybe Rational
- durationOfRepeatedDuration :: Duration -> Rational -> Duration
- durationFromDividingDuration :: Duration -> Rational -> Maybe Duration
- durationIntoDuration :: Duration -> Duration -> Maybe Rational
- negateDuration :: Duration -> Duration
- compareDurationsWithEpsilon :: Duration -> Duration -> Duration -> Ordering
- delayThreadByDuration :: Duration -> IO ()
- data StartOfDuration
- startMeasuring :: IO StartOfDuration
- durationSince :: StartOfDuration -> IO Duration
- measurementEpsilon :: IO Duration
The Duration
type
Represents a span of time using some number of flicks. To create a Duration
use:
durationFromFlicks
durationFromHours
durationFromMicroseconds
durationFromMilliseconds
durationFromMinutes
durationFromSeconds
Duration
can be concatinated with mappend
or the '(<>)' operator.
Constant Ratios
flicksPerMillisecond :: Num a => a Source #
Flicks are a small unit of time that are very evenly divisible by common file format time durations; i.e., for common durations they will have no rounding. Even if there is rounding, it is a very short amount of time -- 1.417 nanoseconds, so rounding is typically not a concern.
flicksPerSecond :: Num a => a Source #
How many flicks are in a second
flicksPerMinute :: Num a => a Source #
How many flicks are in a minute
flickRatio :: Fractional a => a Source #
Ratio
of seconds to flicks. for example, 100 seconds of flicks is (100 * flickRatio)
Duration
to various human units
durationAsHours :: Duration -> Rational Source #
given some Duration
, represent it as a count of hours
durationAsNanoseconds :: Duration -> Rational Source #
given some Duration
, represent it as a count of nanoseconds
durationAsMicroseconds :: Duration -> Rational Source #
given some Duration
, represent it as a count of microseconds
durationAsMilliseconds :: Duration -> Rational Source #
given some Duration
, represent it as a count of milliseconds
durationAsMinutes :: Duration -> Rational Source #
given some Duration
, represent it as a count of minutes
durationAsSeconds :: Duration -> Rational Source #
given some Duration
, represent it as a count of seconds
durationAsHms :: Duration -> (Integer, Integer, Integer, Integer, Integer) Source #
present a Duration
as a count of hours, minutes, seconds, ms, us
Creating Duration
from various human units
durationFromFlicks :: Integral a => a -> Duration Source #
Given a number of flicks, produce a Duration
durationFromNanoseconds :: Rational -> Duration Source #
Given a number of nanoseconds, produce a Duration
.
Note that flicks are larger than nanoseconds, so rounding will occur
durationFromMicroseconds :: Rational -> Duration Source #
Given a number of microseconds, produce a Duration
durationFromMilliseconds :: Rational -> Duration Source #
Given a number of milliseconds, produce a Duration
Duration
from wavelength at some frequency, and vice versa
durationOfOneBeatAtBPM :: Rational -> Maybe Duration Source #
given some frequency in beats per minute, produce the Duration
between beats
durationOfOneCycleAtHz :: Rational -> Maybe Duration Source #
given some frequency in cycles per second, produce the Duration
of a single wavelength's period
frequencyInHzForWavePeriod :: Duration -> Maybe Rational Source #
If Duration
d is the time for one period of a wave, produce the corresponding frequency in hz.
Duration
manipulations
durationOfRepeatedDuration :: Duration -> Rational -> Duration Source #
Repeat a Duration
some rational number of times to produce the total duration
durationFromDividingDuration :: Duration -> Rational -> Maybe Duration Source #
take a Duration
and divide it into equal pieces of some length (the result)
durationIntoDuration :: Duration -> Duration -> Maybe Rational Source #
given some Duration
d1, how many times can we iterate that duration into another duration
compareDurationsWithEpsilon :: Duration -> Duration -> Duration -> Ordering Source #
Given an epsilon e and two durations, will determine their Ord
with respect to the epsilon
Thread delay
delayThreadByDuration :: Duration -> IO () Source #
Suspend currently running thread for a Duration
of time.
Provides no exact guarantee on when the thread will be resumed after the delay.
Measuring delay with the system clock
data StartOfDuration Source #
Holds implementation-defined start of time measurment for startMeasuring
startMeasuring :: IO StartOfDuration Source #
start measuring a duration
durationSince :: StartOfDuration -> IO Duration Source #
How long since the start of measuring has it mean, plus or minus measurementEpsilon
measurementEpsilon :: IO Duration Source #
About how accurate is are the methods durationSince
and startMeasuring