flick-duration-1.0.0: work with durations of time using the Flick as the smallest unit

Copyright(c) 2018 Christopher C Lord Pliosoft
LicenseBSD Style
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Data.Duration

Contents

Description

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

The Duration type

data Duration Source #

Represents a span of time using some number of flicks. To create a Duration use:

Duration can be concatinated with mappend or the '(<>)' operator.

Instances
Eq Duration Source # 
Instance details

Defined in Data.Duration

Ord Duration Source # 
Instance details

Defined in Data.Duration

Show Duration Source # 
Instance details

Defined in Data.Duration

Semigroup Duration Source # 
Instance details

Defined in Data.Duration

Monoid Duration Source # 
Instance details

Defined in Data.Duration

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)

durationToRationalFlicks :: Duration -> Rational Source #

Convert a Duration into flicks, stored in a Rational

durationToRationalSeconds :: Duration -> Rational Source #

Convert a Duration into seconds, stored in a Rational

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

durationFromHours :: Rational -> Duration Source #

Given a number of hours, 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

durationFromMinutes :: Rational -> Duration Source #

Given a number of minutes, produce a Duration

durationFromSeconds :: Rational -> Duration Source #

Given a number of seconds, 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

negateDuration :: Duration -> Duration Source #

given some Duration produce a negative version

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