struct

Quartz::Duration

Inherits JSON::Serializable / Comparable / Struct / Value / Object

Duration is a fixed-point time data type which encapsulates a 64-bit binary floating-point number.

Constants

EPOCH = 5

The epoch constant helps establishing the limiting multiplier of the Duration datatype together with Scale::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 Duration type.

The 1000^5 limit is chosen as the largest power of 1000 less than 2^53, the point at which Float64 ceases 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)
Source
new(m : Number = 0_i64, precision : Scale = Scale::BASE, fixed : Bool = false)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Class methods

from(n : Float)

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)
Source
infinity(precision : Scale = Scale::BASE, fixed : Bool = false)
Source
zero(precision : Scale = Scale::BASE, fixed : Bool = false)
Source

Instance methods

*(n : Number) : Duration

Multiply self by the given factor n.

Source
+(other : Duration) : Duration

Adds two Durations values.

Source
-(other : Duration) : Duration

Substracts two Durations values

Source
-

Negates self.

Source
/(n : Number) : Duration

Divide self by the given scalar operand n.

Source
/(other : Duration) : Float64

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.

Source
<=>(other : self)

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.

Source
clone

Returns a copy of self with all instance variables cloned.

Source
equals?(other : self)

Equality — Returns true only if self and other are equivalent in both multiplier and time precision.

Source
finite?

Whether self is a finite duration.

Source
fixed

Produces a fixed but equivalent duration.

Source
fixed?

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.

Source
fixed_at(precision : Scale) : Duration

Produces a fixed duration value with the specified precision level.

Source
infinite?

Whether self is an infinite duration.

Source
inspect(io)
Source
multiplier

Returns the multiplier of self.

Source
precision
Source
rescale(precision : Scale) : Duration

Produces a duration value with the specified precision level.

Neither fixes or unfixes the time precision of the result.

Source
to_f
Source
to_f32
Source
to_f64
Source
unfixed

Produces an unfixed but equivalent duration.

Source
zero?

Whether self is a zero duration.

Source