Class: OpenHAB::CoreExt::Java::MonthDay
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?
#within?
Class Method Details
.parse(string) ⇒ MonthDay
Parses strings in the form "M-d"
23
24
25
26
27
28
29
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 23
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
43
44
45
46
47
48
49
50
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 43
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
|
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 53
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.
72
73
74
75
76
77
78
79
80
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 72
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
99
100
101
102
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 99
def to_date(context = nil)
context ||= Date.today
Date.new(context.year, month_value, day_of_month)
end
|
#to_instant(context = nil) ⇒ Instant
121
122
123
124
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 121
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
86
87
88
89
90
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 86
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
93
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 93
alias_method :to_month, :month
|
#to_month_day ⇒ self
105
106
107
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 105
def to_month_day
self
end
|
#to_s ⇒ String
Also known as:
inspect
33
34
35
36
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 33
def to_s
to_string.delete_prefix("--")
end
|
#to_zoned_date_time(context = nil) ⇒ ZonedDateTime
113
114
115
|
# File 'lib/openhab/core_ext/java/month_day.rb', line 113
def to_zoned_date_time(context = nil)
to_local_date(context).to_zoned_date_time(context)
end
|