Class: OpenHAB::CoreExt::Java::LocalDate

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

Overview

Extensions to javajava.timejava.time.LocalDate

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ephemeris

#days_until, #holiday, #holiday?, #in_dayset?, #next_holiday, #weekend?

Methods included from Between

#between?

Methods included from Time

#<=>, #coerce

Class Attribute Details

.nowLocalDate (readonly)

Returns:



# File 'lib/openhab/core_ext/java/local_date.rb', line 18

Class Method Details

.parse(text, formatter = nil) ⇒ LocalDate

Converts the given text into a LocalDate.

Parameters:

  • text (String)

    The text to parse

  • formatter (java.time.format.DateTimeFormatter) (defaults to: nil)

    The formatter to use

Returns:



# File 'lib/openhab/core_ext/java/local_date.rb', line 21

Instance Method Details

#+(other) ⇒ LocalDate

Parameters:

Returns:



53
54
55
56
57
58
59
60
61
62
# File 'lib/openhab/core_ext/java/local_date.rb', line 53

def +(other)
  case other
  when Duration
    plus_days(other.to_days)
  when Numeric
    plus_days(other.to_i)
  else
    plus(other)
  end
end

#-(other) ⇒ LocalDate, Period

Parameters:

Returns:

  • (LocalDate)

    If other is a TemporalAmount or Numeric

  • (Period)

    If other is a LocalDate



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/openhab/core_ext/java/local_date.rb', line 33

def -(other)
  case other
  when Date
    self - other.to_local_date
  when MonthDay
    self - other.at_year(year)
  when LocalDate
    Period.between(other, self)
  when Duration
    minus_days(other.to_days)
  when Numeric
    minus_days(other.ceil)
  else
    minus(other)
  end
end

#succLocalDate

Returns the next day

Returns:



69
70
71
# File 'lib/openhab/core_ext/java/local_date.rb', line 69

def succ
  plus_days(1)
end

#to_dateDate

Returns:



74
75
76
# File 'lib/openhab/core_ext/java/local_date.rb', line 74

def to_date
  Date.new(year, month_value, day_of_month)
end

#to_local_date(_context = nil) ⇒ self

Returns:

  • (self)


87
88
89
# File 'lib/openhab/core_ext/java/local_date.rb', line 87

def to_local_date(_context = nil)
  self
end

#to_month_dayMonthDay

Returns:



82
83
84
# File 'lib/openhab/core_ext/java/local_date.rb', line 82

def to_month_day
  MonthDay.of(month, day_of_month)
end

#to_zoned_date_time(context = nil) ⇒ ZonedDateTime

Parameters:

Returns:



95
96
97
98
# File 'lib/openhab/core_ext/java/local_date.rb', line 95

def to_zoned_date_time(context = nil)
  zone = context&.zone || java.time.ZoneId.system_default
  at_start_of_day(zone)
end