Class: OpenHAB::CoreExt::Java::MonthDay
- Inherits:
-
Object
- Object
- OpenHAB::CoreExt::Java::MonthDay
show all
- Includes:
- Between, Ephemeris, Time
- Defined in:
- lib/openhab/core_ext/java/month_day.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Time
#<=>, #coerce
Methods included from Ephemeris
#days_until, #holiday, #holiday?, #in_dayset?, #next_holiday, #weekend?
Methods included from Between
#between?
Class Method Details
.parse(string) ⇒ MonthDay
Parses strings in the form "M-d"
22
23
24
25
26
27
28
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 22
def parse(string)
logger.trace { "#{self.class}.parse #{string} (#{string.class})" }
java_send(:parse,
[java.lang.CharSequence, java.time.format.DateTimeFormatter],
string.to_s,
java.time.format.DateTimeFormatter.ofPattern("[--]M-d"))
end
|
Instance Method Details
42
43
44
45
46
47
48
49
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 42
def +(other)
case other
when java.time.temporal.TemporalAmount, Numeric
(LocalDate.of(1900, month, day_of_month) + other).to_month_day
else
(to_local_date(other.to_local_date) + other).to_month_day
end
end
|
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 52
def -(other)
d = case other
when java.time.temporal.TemporalAmount, Numeric
LocalDate.of(1900, month, day_of_month) - other
else
to_local_date(other.to_local_date) - other
end
return d if d.is_a?(java.time.Period)
d.to_month_day
end
|
Returns the next day
Will go to the next month, or loop back to January if necessary.
71
72
73
74
75
76
77
78
79
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 71
def succ
if day_of_month == month.max_length
return MonthDay.of(1, 1) if month_value == 12
return MonthDay.of(month_value + 1, 1)
end
MonthDay.of(month_value, day_of_month + 1)
end
|
#to_date(context = nil) ⇒ Date
98
99
100
101
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 98
def to_date(context = nil)
context ||= Date.today
Date.new(context.year, month_value, day_of_month)
end
|
#to_instant(context = nil) ⇒ Instant
120
121
122
123
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 120
def to_instant(context = nil)
context ||= Instant.now.to_zoned_date_time
to_local_date(context).to_instant
end
|
#to_local_date(context = nil) ⇒ LocalDate
85
86
87
88
89
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 85
def to_local_date(context = nil)
context ||= java.time.Year.now
year = java.time.Year.from(context)
year.at_month_day(self)
end
|
#to_month ⇒ Month
92
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 92
alias_method :to_month, :month
|
#to_month_day ⇒ self
104
105
106
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 104
def to_month_day
self
end
|
#to_s ⇒ String
Also known as:
inspect
32
33
34
35
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 32
def to_s
to_string.delete_prefix("--")
end
|
#to_zoned_date_time(context = nil) ⇒ ZonedDateTime
112
113
114
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 112
def to_zoned_date_time(context = nil)
to_local_date(context).to_zoned_date_time(context)
end
|