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 java.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:

Returns:



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

Instance Method Details

#+(other) ⇒ LocalDate

Parameters:

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openhab/core_ext/java/local_date.rb', line 55

def +(other)
  case other
  when Duration
    plus_days(other.to_days)
  when Numeric
    plus_days(other.to_i)
  when QuantityType
    plus_days(other.to_temporal_amount.to_days)
  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
49
50
# 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)
  when QuantityType
    minus_days(other.to_temporal_amount.to_days)
  else
    minus(other)
  end
end

#succLocalDate

Returns the next day

Returns:



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

def succ
  plus_days(1)
end

#to_dateDate

Returns:



78
79
80
# File 'lib/openhab/core_ext/java/local_date.rb', line 78

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

#to_instant(context = nil) ⇒ Instant

Parameters:

Returns:



108
109
110
# File 'lib/openhab/core_ext/java/local_date.rb', line 108

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

#to_local_date(_context = nil) ⇒ self

Returns:

  • (self)


91
92
93
# File 'lib/openhab/core_ext/java/local_date.rb', line 91

def to_local_date(_context = nil)
  self
end

#to_monthMonth

Returns:



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

alias_method :to_month, :month

#to_month_dayMonthDay

Returns:



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

def to_month_day
  MonthDay.of(month, day_of_month)
end

#to_zoned_date_time(context = nil) ⇒ ZonedDateTime

Parameters:

Returns:



99
100
101
102
# File 'lib/openhab/core_ext/java/local_date.rb', line 99

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