Module: OpenHAB::CoreExt::Ephemeris

Included in:
Date, DateTime, Java::LocalDate, Java::MonthDay, Time
Defined in:
lib/openhab/core_ext/ephemeris.rb

Overview

Note:

openHAB’s built-in holiday definitions are based on bank holidays, so may give some unexpected results. For example, 2022-12-25 is not Christmas in England because it lands on a Sunday that year, so Christmas is considered to be 2022-12-26. See [the source](github.com/svendiedrichsen/jollyday/tree/master/src/main/resources/holidays) for exact definitions. You can always provide your own holiday definitions with holiday_file or holiday_file!.

Forwards ephemeris helper methods to ‘#to_zoned_date_time` provided by the mixed-in class.

Instance Method Summary collapse

Instance Method Details

#days_until(holiday, holiday_file = nil) ⇒ Integer

Calculate the number of days until a specific holiday

Examples:

Time.now.days_until(:christmas) # => 2

Parameters:

  • holiday (String, Symbol)
  • holiday_file (String, nil) (defaults to: nil)

    Optional path to XML file to use for holiday definitions.

Returns:

Raises:

  • (ArgumentError)

    if the holiday isn’t valid



48
49
50
# File 'lib/openhab/core_ext/ephemeris.rb', line 48

def days_until(holiday, holiday_file = nil)
  to_zoned_date_time.days_until(holiday, holiday_file)
end

#holiday(holiday_file = nil) ⇒ Symbol?

Name of the holiday for this date.

Examples:

MonthDay.parse("12-25").holiday # => :christmas

Parameters:

  • holiday_file (String, nil) (defaults to: nil)

    Optional path to XML file to use for holiday definitions.

Returns:



23
24
25
# File 'lib/openhab/core_ext/ephemeris.rb', line 23

def holiday(holiday_file = nil)
  to_zoned_date_time.holiday(holiday_file)
end

#holiday?(holiday_file = nil) ⇒ true, false

Determines if this date is on a holiday.

Parameters:

  • holiday_file (String, nil) (defaults to: nil)

    Optional path to XML file to use for holiday definitions.

Returns:

  • (true, false)


28
29
30
# File 'lib/openhab/core_ext/ephemeris.rb', line 28

def holiday?(holiday_file = nil)
  to_zoned_date_time.holiday?(holiday_file)
end

#in_dayset?(set) ⇒ true, false

Determines if this time is during a specific dayset

Examples:

Time.now.in_dayset?("school")

Parameters:

Returns:

  • (true, false)


43
44
45
# File 'lib/openhab/core_ext/ephemeris.rb', line 43

def in_dayset?(set)
  to_zoned_date_time.in_dayset?(set)
end

#next_holiday(holiday_file = nil) ⇒ Symbol

Name of the closest holiday on or after this date.

Parameters:

  • holiday_file (String, nil) (defaults to: nil)

    Optional path to XML file to use for holiday definitions.

Returns:



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

def next_holiday(holiday_file = nil)
  to_zoned_date_time.next_holiday(holiday_file)
end

#weekend?true, false

Determines if this time is during a weekend.

Examples:

Time.now.weekend?

Returns:

  • (true, false)


38
39
40
# File 'lib/openhab/core_ext/ephemeris.rb', line 38

def weekend?
  to_zoned_date_time.weekend?
end