struct Quartz::Duration
- Quartz::Duration
- Struct
- Value
- Object
Overview
Duration is a fixed-point time data type which encapsulates a 64-bit
binary floating-point number.
Included Modules
- Comparable(Quartz::Duration)
- JSON::Serializable
Defined in:
quartz/duration.crquartz/json.cr
Constant Summary
-
EPOCH =
5 -
The epoch constant helps establishing the limiting multiplier of the
Durationdatatype together withScale::FACTOR. -
INFINITY =
new(MULTIPLIER_INFINITE) -
An infinite duration with a base scale.
-
MULTIPLIER_INFINITE =
Float64::INFINITY -
The infinite multiplier
-
MULTIPLIER_LIMIT =
Scale::FACTOR ** EPOCH -
The limiting multiplier of the
Durationtype.The 1000^5 limit is chosen as the largest power of 1000 less than 2^53, the point at which
Float64ceases to exactly represent all integers. -
MULTIPLIER_MAX =
MULTIPLIER_LIMIT - 1 -
The largest finite multiplier that can be represented by a
Duration. -
MULTIPLIER_MIN =
0_i64 -
The smallest finite multiplier that can be represented by a
Duration.
Constructors
- .new(m : Number = 0_i64, precision : Int = 0_i8, fixed : Bool = false)
- .new(m : Number = 0_i64, precision : Scale = Scale::BASE, fixed : Bool = false)
- .new(pull : JSON::PullParser)
Class Method Summary
-
.from(n : Float)
Creates a
Durationfrom a givenFloatbetween 0 and 1 and tries to assign an appropriate precision. - .infinity(precision : Scale = Scale::BASE, fixed : Bool = false)
- .zero(precision : Scale = Scale::BASE, fixed : Bool = false)
Instance Method Summary
-
#*(n : Number) : Duration
Multiply
selfby the given factor n. -
#+(other : Duration) : Duration
Adds two
Durations values. -
#-(other : Duration) : Duration
Substracts two
Durations values -
#- : Duration
Negates
self. -
#/(n : Number) : Duration
Divide
selfby the given scalar operand n. -
#/(other : Duration) : Float64
The division of one duration by another is always considered a floating-point operation.
-
#<=>(other : self)
Implements the comparison operator.
-
#clone
Returns a copy of
selfwith all instance variables cloned. -
#equals?(other : self)
Equality — Returns
trueonly ifselfand other are equivalent in both multiplier and time precision. -
#finite? : Bool
Whether
selfis a finite duration. -
#fixed : Duration
Produces a fixed but equivalent duration.
-
#fixed? : Bool
Whether
selffixed or unfixed. -
#fixed_at(precision : Scale) : Duration
Produces a fixed duration value with the specified precision level.
-
#infinite? : Bool
Whether
selfis an infinite duration. - #inspect(io)
-
#multiplier : Int64
Returns the multiplier of
self. - #precision : Scale
-
#rescale(precision : Scale) : Duration
Produces a duration value with the specified precision level.
- #to_f
- #to_f32
- #to_f64
-
#unfixed : Duration
Produces an unfixed but equivalent duration.
-
#zero? : Bool
Whether
selfis a zero duration.
Instance methods inherited from struct Value
==(other : Quartz::Any)
==
Instance methods inherited from class Object
===(other : Quartz::Any)
===
Constructor Detail
Class Method Detail
Creates a Duration from a given Float between 0 and 1 and tries to
assign an appropriate precision.
Duration.from(0.000034) # => Duration.new(34, Scale::MICRO)
Instance Method Detail
The division of one duration by another is always considered a floating-point operation.
The numerator and denominator may have different precision levels and the result is a scalar with no prescribed precision.
Implements the comparison operator.
Assumes that self and other could be replaced by their associated
quantities. As a consequence, two Duration values can be considered equal
with different precision levels.
Equality — Returns true only if self and other are equivalent in both
multiplier and time precision.
Whether self fixed or unfixed. When fixed, the time precision is preserved
through operations. Otherwise, the time precision may be altered to minimize
rounding error.
By default, Duration values are unfixed, which makes it easy to express
durations using combinations of multiples of base-1000 SI units.
Produces a fixed duration value with the specified precision level.
Produces a duration value with the specified precision level.
Neither fixes or unfixes the time precision of the result.