struct Quartz::Duration

Overview

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

Included Modules

Defined in:

quartz/duration.cr

Constant Summary

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

Class Method Summary

Instance Method Summary

Instance methods inherited from struct Value

==(other : Quartz::Any) ==

Instance methods inherited from class Object

===(other : Quartz::Any) ===

Constructor Detail

def self.new(m : Number = 0_i64, precision : Int = 0_i8, fixed : Bool = false) #

[View source]
def self.new(m : Number = 0_i64, precision : Scale = Scale::BASE, fixed : Bool = false) #

[View source]

Class Method Detail

def self.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)

[View source]
def self.infinity(precision : Scale = Scale::BASE, fixed : Bool = false) #

[View source]
def self.zero(precision : Scale = Scale::BASE, fixed : Bool = false) #

[View source]

Instance Method Detail

def *(n : Number) : Duration #

Multiply self by the given factor n.


[View source]
def +(other : Duration) : Duration #

Adds two Durations values.


[View source]
def -(other : Duration) : Duration #

Substracts two Durations values


[View source]
def - : Duration #

Negates self.


[View source]
def /(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.


[View source]
def /(n : Number) : Duration #

Divide self by the given scalar operand n.


[View source]
def <=>(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.


[View source]
def clone #

Returns a copy of self with all instance variables cloned.


[View source]
def equals?(other : self) #

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


[View source]
def finite? : Bool #

Whether self is a finite duration.


[View source]
def fixed : Duration #

Produces a fixed but equivalent duration.


[View source]
def fixed? : Bool #

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.


[View source]
def fixed_at(precision : Scale) : Duration #

Produces a fixed duration value with the specified precision level.


[View source]
def infinite? : Bool #

Whether self is an infinite duration.


[View source]
def inspect(io) #

[View source]
def multiplier : Int64 #

Returns the multiplier of self.


[View source]
def precision : Scale #

[View source]
def rescale(precision : Scale) : Duration #

Produces a duration value with the specified precision level.

Neither fixes or unfixes the time precision of the result.


[View source]
def to_f #

[View source]
def to_f32 #

[View source]
def to_f64 #

[View source]
def unfixed : Duration #

Produces an unfixed but equivalent duration.


[View source]
def zero? : Bool #

Whether self is a zero duration.


[View source]