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:



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

def +(other)
  plus(other)
end

#-(other) ⇒ Month

Returns:



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

def -(other)
  minus(other)
end

#succMonth

Returns the next month

Will loop back to January if necessary.

Returns:



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

def succ
  plus(1)
end

#to_date(context = nil) ⇒ Date

Returns:



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

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:



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

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:



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

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)


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

def to_month
  self
end

#to_month_dayMonthDay

Returns:



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

def to_month_day
  MonthDay.of(self, 1)
end

#to_zoned_date_time(context = nil) ⇒ ZonedDateTime

Parameters:

Returns:



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

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