Module: OpenHAB::CoreExt::Java::Time

Included in:
LocalDate, Month, MonthDay, ZonedDateTime
Defined in:
lib/openhab/core_ext/java/time.rb

Overview

Common extensions to Java Date/Time classes

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Integer

Compare against another time object

Parameters:

  • other (Object)

    The other time object to compare against.

Returns:

  • (Integer)

    -1, 0, +1 depending on whether ‘other` is less than, equal to, or greater than self



40
41
42
43
44
45
46
47
48
# File 'lib/openhab/core_ext/java/time.rb', line 40

def <=>(other)
  if other.is_a?(self.class)
    compare_to(other)
  elsif other.respond_to?(:coerce)
    return nil unless (lhs, rhs = other.coerce(self))

    lhs <=> rhs
  end
end

#coerce(other) ⇒ Array?

Convert ‘other` to this class, if possible

Returns:



52
53
54
55
56
57
58
# File 'lib/openhab/core_ext/java/time.rb', line 52

def coerce(other)
  coercion_method = self.class.coercion_method
  return unless other.respond_to?(coercion_method)
  return [other.send(coercion_method), self] if other.method(coercion_method).arity.zero?

  [other.send(coercion_method, self), self]
end