Class: Horologium::Duration
- Inherits:
-
Object
- Object
- Horologium::Duration
- Includes:
- PreciseValue
- Defined in:
- lib/horologium/duration.rb,
sig/horologium/duration.rbs
Overview
An amount of time in SI seconds, with no date and no scale attached.
Duration.days(1) is always 86,400 SI seconds. Because of leap seconds a
civil day can be a second longer or shorter, so a Duration and a calendar
day are different things.
A Duration is frozen. Its precision is set when it is built, from the
precision in effect unless you pass one. At :standard it holds the
seconds as a Numeric::TwoPartFloat, at :exact as a Numeric::Exact.
Constant Summary collapse
- SECONDS_PER_DAY =
The number of SI seconds in a day.
86_400- NANOSECONDS_PER_SECOND =
The number of nanoseconds in a second.
1_000_000_000
Instance Attribute Summary
Attributes included from PreciseValue
Class Method Summary collapse
-
.days(count, precision: Horologium.current_precision) ⇒ Horologium::Duration
A duration of
countdays, each of SECONDS_PER_DAY SI seconds. -
.nanoseconds(count, precision: Horologium.current_precision) ⇒ Horologium::Duration
A duration of
countnanoseconds. -
.seconds(count, precision: Horologium.current_precision) ⇒ Horologium::Duration
A duration of
countSI seconds.
Instance Method Summary collapse
-
#abs ⇒ Horologium::Duration
The same length, never negative.
Methods included from PreciseValue
#<=>, #eql?, #hash, #initialize
Class Method Details
.days(count, precision: Horologium.current_precision) ⇒ Horologium::Duration
A duration of count days, each of SECONDS_PER_DAY SI seconds. This
counts time and is not tied to the calendar.
48 49 50 |
# File 'lib/horologium/duration.rb', line 48 def days(count, precision: Horologium.current_precision) from_seconds(count * SECONDS_PER_DAY, precision) end |
.nanoseconds(count, precision: Horologium.current_precision) ⇒ Horologium::Duration
A duration of count nanoseconds.
60 61 62 |
# File 'lib/horologium/duration.rb', line 60 def nanoseconds(count, precision: Horologium.current_precision) from_seconds(Rational(count) / NANOSECONDS_PER_SECOND, precision) end |
.seconds(count, precision: Horologium.current_precision) ⇒ Horologium::Duration
A duration of count SI seconds.
34 35 36 |
# File 'lib/horologium/duration.rb', line 34 def seconds(count, precision: Horologium.current_precision) from_seconds(count, precision) end |
Instance Method Details
#abs ⇒ Horologium::Duration
The same length, never negative.
92 93 94 |
# File 'lib/horologium/duration.rb', line 92 def abs rational.negative? ? self.class.new(value * -1, precision) : self end |