Module: OpenHAB::DSL
- Defined in:
- lib/rspec/openhab/dsl/imports.rb,
lib/rspec/openhab/dsl/rules/rspec.rb,
lib/rspec/openhab/dsl/timers/timer.rb,
lib/rspec/openhab/core/script_handling.rb
Defined Under Namespace
Modules: Core, Imports, Rules Classes: Timer
Class Method Summary collapse
-
.seconds_to_duration(secs) ⇒ Duration
Convert numeric seconds to a Duration object.
-
.to_zdt(timestamp) ⇒ ZonedDateTime
Convert TemporalAmount (Duration), seconds (float, integer), and Ruby Time to ZonedDateTime Note: TemporalAmount is added to now.
Class Method Details
.seconds_to_duration(secs) ⇒ Duration
Convert numeric seconds to a Duration object
77 78 79 80 81 82 83 84 85 |
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 77 def self.seconds_to_duration(secs) return unless secs if secs.respond_to?(:to_f) secs.to_f.seconds elsif secs.respond_to?(:to_i) secs.to_i.seconds end end |
.to_zdt(timestamp) ⇒ ZonedDateTime
Convert TemporalAmount (Duration), seconds (float, integer), and Ruby Time to ZonedDateTime Note: TemporalAmount is added to now
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rspec/openhab/dsl/timers/timer.rb', line 56 def self.to_zdt() logger.trace("Converting #{} (#{.class}) to ZonedDateTime") return unless case when Java::JavaTimeTemporal::TemporalAmount then ZonedDateTime.now.plus() when ZonedDateTime then when Time then .to_java(ZonedDateTime) else to_zdt(seconds_to_duration()) || raise(ArgumentError, "Timestamp must be a ZonedDateTime, a Duration, a Numeric, or a Time object") end end |