Class: OpenHAB::CoreExt::Java::Period

Inherits:
Object
  • Object
show all
Includes:
TemporalAmount
Defined in:
lib/openhab/core_ext/java/period.rb

Overview

Extensions to javajava.timejava.time.Period

Instance Method Summary collapse

Methods included from TemporalAmount

#-@, #ago, #from_now, #inspect

Instance Method Details

#<=>(other) ⇒ Integer?

Returns:



37
38
39
40
41
# File 'lib/openhab/core_ext/java/period.rb', line 37

def <=>(other)
  return to_i <=> other if other.is_a?(Numeric)

  super
end

#coerce(other) ⇒ Array?

Convert ‘self` and `other` to Duration, if `other` is a Numeric

Parameters:

Returns:



49
50
51
# File 'lib/openhab/core_ext/java/period.rb', line 49

def coerce(other)
  [other.seconds, to_i.seconds] if other.is_a?(Numeric)
end

#to_fFloat

Convert to number of seconds

Returns:



30
31
32
# File 'lib/openhab/core_ext/java/period.rb', line 30

def to_f
  to_i.to_f
end

#to_iInteger

Convert to number of seconds

Returns:



17
18
19
20
21
22
23
# File 'lib/openhab/core_ext/java/period.rb', line 17

def to_i
  [java.time.temporal.ChronoUnit::YEARS,
   java.time.temporal.ChronoUnit::MONTHS,
   java.time.temporal.ChronoUnit::DAYS].sum do |unit|
    get(unit) * unit.duration.to_i
  end
end