Module: OpenHAB::CoreExt::TimePredicates
- Included in:
- Date, DateTime, Java::Instant, Java::LocalDate, Java::LocalTime, Java::Month, Java::MonthDay, Java::ZonedDateTime, Time
- Defined in:
- lib/openhab/core_ext/time_predicates.rb
Overview
Predicate helpers for date/time-like objects.
Instance Method Summary collapse
-
#within?(epsilon, of: ZonedDateTime.now) ⇒ true, false
Checks whether the object is within a maximum allowable distance (epsilon) of a specific anchor time.
Instance Method Details
#within?(epsilon, of: ZonedDateTime.now) ⇒ true, false
Checks whether the object is within a maximum allowable distance (epsilon) of a specific anchor time.
21 22 23 24 25 |
# File 'lib/openhab/core_ext/time_predicates.rb', line 21 def within?(epsilon, of: ZonedDateTime.now) # Convert times to a common float representation (like epoch seconds) to do the math # Or use native Java duration differences if keeping it in the Java ecosystem (of - self).to_f.abs < epsilon.to_f end |