Module: OpenHAB::CoreExt::Java::Time
- Included in:
- Instant, 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
-
#<=>(other) ⇒ Integer
Compare against another time object.
-
#coerce(other) ⇒ Array?
Convert
other
to this class, if possible.
Instance Method Details
#<=>(other) ⇒ Integer
Compare against another time object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/openhab/core_ext/java/time.rb', line 40 def <=>(other) logger.trace { "(#{self.class}) #{self} <=> #{other} (#{other.class})" } 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
53 54 55 56 57 58 59 60 |
# File 'lib/openhab/core_ext/java/time.rb', line 53 def coerce(other) logger.trace { "Coercing #{self} as a request from #{other.class}" } 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 |