Class: OpenHAB::CoreExt::Java::Month

Inherits:
Object
  • Object
show all
Includes:
Between, Time
Defined in:
lib/openhab/core_ext/java/month.rb

Overview

Extensions to java.time.Month

Instance Method Summary collapse

Methods included from Time

#<=>, #coerce

Methods included from Between

#between?

Instance Method Details

#+(other) ⇒ Month

Returns:



17
18
19
# File 'lib/openhab/core_ext/java/month.rb', line 17

def +(other)
  plus(other)
end

#-(other) ⇒ Month

Returns:



22
23
24
# File 'lib/openhab/core_ext/java/month.rb', line 22

def -(other)
  minus(other)
end

#succMonth

Returns the next month

Will loop back to January if necessary.

Returns:



33
34
35
# File 'lib/openhab/core_ext/java/month.rb', line 33

def succ
  plus(1)
end

#to_date(context = nil) ⇒ Date

Returns:



45
46
47
# File 'lib/openhab/core_ext/java/month.rb', line 45

def to_date(context = nil)
  to_local_date(context).to_date
end

#to_instant(context = nil) ⇒ Instant

Parameters:

  • context (ZonedDateTime, nil) (defaults to: nil)

    A ZonedDateTime used to fill in the year during conversion, with the date set to the first day of the month. Instant.now is assumed if not given.

Returns:



72
73
74
75
# File 'lib/openhab/core_ext/java/month.rb', line 72

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

Returns:



38
39
40
41
42
# File 'lib/openhab/core_ext/java/month.rb', line 38

def to_local_date(context = nil)
  context ||= java.time.Year.now
  year = java.time.Year.from(context)
  year.at_month_day(to_month_day)
end

#to_monthself

Returns:

  • (self)


50
51
52
# File 'lib/openhab/core_ext/java/month.rb', line 50

def to_month
  self
end

#to_month_dayMonthDay

Returns:



55
56
57
# File 'lib/openhab/core_ext/java/month.rb', line 55

def to_month_day
  MonthDay.of(self, 1)
end

#to_zoned_date_time(context = nil) ⇒ ZonedDateTime

Parameters:

Returns:



63
64
65
# File 'lib/openhab/core_ext/java/month.rb', line 63

def to_zoned_date_time(context = nil)
  to_local_date(context).to_zoned_date_time(context)
end