Class: OpenHAB::CoreExt::Java::LocalTime
- Inherits:
-
Object
- Object
- OpenHAB::CoreExt::Java::LocalTime
- Includes:
- Between
- Defined in:
- lib/openhab/core_ext/java/local_time.rb
Overview
Extensions to java.time.LocalTime
Class Attribute Summary collapse
- .now ⇒ LocalTime readonly
Class Method Summary collapse
-
.parse(string, formatter = nil) ⇒ LocalTime
Parses strings in the form "h[:mm[:ss]] [am/pm]" when no formatter is given.
Instance Method Summary collapse
- #+(other) ⇒ LocalTime
- #-(other) ⇒ LocalTime
-
#succ ⇒ LocalTime
Returns the next second.
-
#to_instant(context = nil) ⇒ Instant
Converts the LocalTime (in the system timezone) to an Instant (in Zulu time).
- #to_local_time ⇒ self
- #to_zoned_date_time(context = nil) ⇒ ZonedDateTime
Methods included from Between
Class Attribute Details
Class Method Details
.parse(string, formatter = nil) ⇒ LocalTime
Parses strings in the form "h[:mm[:ss]] [am/pm]" when no formatter is given.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 55 def parse(string, formatter = nil) return raw_parse(string, formatter) if formatter format = /(am|pm)$/i.match?(string) ? "h[:mm[:ss][.S]][ ]a" : "H[:mm[:ss][.S]]" java_send(:parse, [java.lang.CharSequence, java.time.format.DateTimeFormatter], string, java.time.format.DateTimeFormatterBuilder.new .parse_case_insensitive .parse_lenient .append_pattern(format) .to_formatter(java.util.Locale::ENGLISH)) end |
Instance Method Details
#+(other) ⇒ LocalTime
84 85 86 87 88 89 90 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 84 def +(other) return plus(other.seconds) if other.is_a?(Numeric) return self if other.is_a?(Period) other = other.to_temporal_amount if other.is_a?(QuantityType) plus(other) end |
#-(other) ⇒ LocalTime
73 74 75 76 77 78 79 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 73 def -(other) return minus(other.seconds) if other.is_a?(Numeric) return self if other.is_a?(Period) other = other.to_temporal_amount if other.is_a?(QuantityType) minus(other) end |
#succ ⇒ LocalTime
Returns the next second
Will loop back to the beginning of the day if necessary.
99 100 101 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 99 def succ plus_seconds(1) end |
#to_instant(context = nil) ⇒ Instant
Converts the LocalTime (in the system timezone) to an Instant (in Zulu time).
125 126 127 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 125 def to_instant(context = nil) to_zoned_date_time(context).to_instant end |
#to_local_time ⇒ self
104 105 106 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 104 def to_local_time self end |
#to_zoned_date_time(context = nil) ⇒ ZonedDateTime
112 113 114 115 |
# File 'lib/openhab/core_ext/java/local_time.rb', line 112 def to_zoned_date_time(context = nil) context ||= ZonedDateTime.now context.with(self) end |