| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Time.Interval
Description
Suppose you have Settings type, and one of its fields specifies an
amount of time. Suppose you want to use Data.Time.Units for that, because
it abstracts away the direct use or Int or Integer. Using TimeUnit
directly would require to add the concrete time unit type as a type
parameter of Settings (or use GHC type related extensions):
data Settings t = Settings
{ x :: Int
, y :: Text
, z :: t
}And any use of z would require to specify the TimeUnit t => constraint.
If you want to add more settings fields later which are time durations,
you'll need to add more type variables which may break code which uses the
Settings type.
data Settings t1 t2 t3 = Settings
{ x :: Int
, y :: Text
, z :: t1
, u :: t2
, v :: t3
}This package provides something between Int and TimeUnit. A concrete
type for specifying time durations, which both hide the integers and avoid
the type variables:
data Settings = Settings
{ x :: Int
, y :: Text
, z :: TimeInterval
, u :: TimeInterval
, v :: TimeInterval
}There is nothing magical here, this is simply a convenience package for people who encounter this issue in their code.
Note that currently TimeInterval stores time as microseconds internally.
This may be a problem if you plan to work with smaller intervals
(nanoseconds, picoseconds, etc.). If you have such needs, please contact the
maintainer to discuss a solution.
- data TimeInterval
- fromTimeUnit :: TimeUnit t => t -> TimeInterval
- toTimeUnit :: TimeUnit t => TimeInterval -> t
- toMicroUnit :: TimeInterval -> Microsecond
- time :: TimeUnit t => t -> TimeInterval
- microseconds :: TimeInterval -> Integer
Documentation
data TimeInterval Source
A time duration.
fromTimeUnit :: TimeUnit t => t -> TimeInterval Source
Convert a time value expressed in a some time unit into a TimeInterval.
toTimeUnit :: TimeUnit t => TimeInterval -> t Source
Convert a TimeInterval to a TimeUnit instance.
toMicroUnit :: TimeInterval -> Microsecond Source
Specialized toTimeUnit for converting to Microsecond units.
time :: TimeUnit t => t -> TimeInterval Source
Deprecated: Use fromTimeUnit instead
Deprecated alias of fromTimeUnit.
microseconds :: TimeInterval -> Integer Source
Express a TimeInterval in microseconds.