Ephemeris.isBankHoliday false for self defined holidays

Tags: #<Tag:0x00007f5c98aee998>

On my Debian Linux system Ephemeris.isBankHoliday today returns false.
I use a patched Holidays_de.xml where I added SHROVE_MONDAY as

<tns:ChristianHoliday type="SHROVE_MONDAY" />

In the rules file, I use following code:

val String holidayxml = '/etc/openhab2/services/Holidays_de.xml'
val String FeiertagName = Ephemeris.getBankHolidayName(0, holidayxml)
val String FeiertagDesc = Ephemeris.getHolidayDescription(FeiertagName)
logInfo("Holiday", "Heutiger Feiertagsname: "+FeiertagDesc)
logInfo("Holiday", "isBankHoliday: "+Ephemeris.isBankHoliday(0, holidayxml))
if (Ephemeris.isBankHoliday(0, holidayxml) == true) {
       ....
}

While FeiertagDesc is shown as “Aschermontag”, isBankHoliday returns false.
Since EASTER_MONDAY is 49 days away, I changed the “0” everywhere to 49 and now isBankHoliday returns true.

But why doesn’t it accept my SHROVE_MONDAY? Especially if getBankHolidayName/getHolidayDescription seem to accept SHROVE_MONDAY?

As a workaround I currently use

if (Ephemeris.isBankHoliday(0, holidayxml) == true || FeiertagDesc !== null) {

but I’d like to understand, why isBankHoliday doesn’t work for me.

Greetings
Roland

Bonus question: Any idea how to change the description of SHROVE_MONDAY from “Aschermontag” to “Rosenmontag”? I placed a modified holiday_descriptions_de.properties in /etc/openhab2/services, but I don’t know how to tell OpenHAB how to use it.

Seems that I have to answer this myself: It’s just a bug.

    public static boolean isBankHoliday(int offset, String filename) {
        return isBankHoliday(ZonedDateTime.now().plusDays(offset));
    }

simply throws away the filename.

I’ll file a bug report: https://github.com/openhab/openhab-core/issues/1374

Already solved, had no time to open Eclipse ,:yum:

I’m trying to make it work
but I haven’t succeeded
/etc/openhab2/services/Holidays_gr.xml

<?xml version="1.0" encoding="UTF-8"?>

<tns:Configuration hierarchy="gr" description="Greece"

    xmlns:tns="http://www.example.org/Holiday" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.example.org/Holiday /Holiday.xsd">

    <tns:Holidays>

        <tns:Fixed month="JANUARY" day="1" descriptionPropertiesKey="NEW_YEAR"/>

        <tns:Fixed month="JANUARY" day="6" descriptionPropertiesKey="THEOPHANY"/>

        <tns:Fixed month="JANUARY" day="12" descriptionPropertiesKey="CHRIS_BIRTHDAY"/>

        <tns:Fixed month="JANUARY" day="20" descriptionPropertiesKey="Chris_test"/>

        <tns:Fixed month="JANUARY" day="30" descriptionPropertiesKey="THREE_HIERARCHS"/>

        <tns:Fixed month="FEBRUARY" day="25" descriptionPropertiesKey="February_25"/>

        <tns:Fixed month="FEBRUARY" day="26" descriptionPropertiesKey="February_26"/>

        <tns:Fixed month="MARCH" day="6" descriptionPropertiesKey="GEORGE_BIRTHDAY"/>

        <tns:Fixed month="MARCH" day="25" descriptionPropertiesKey="ANNUNCIATION"/>

        <tns:Fixed month="MAY" day="1" descriptionPropertiesKey="LABOUR_DAY"/>

        <tns:Fixed month="MAY" day="4" descriptionPropertiesKey="KONSTANTINE_BIRTHDAY"/>

        <tns:Fixed month="MAY" day="6" descriptionPropertiesKey="OLGA_BIRTHDAY"/>

        <tns:Fixed month="AUGUST" day="15" descriptionPropertiesKey="ASSUMPTION_DAY"/>

        <tns:Fixed month="OCTOBER" day="28" descriptionPropertiesKey="OCHI"/>

        <tns:Fixed month="DECEMBER" day="25" descriptionPropertiesKey="CHRSITMAS"/>

        <tns:Fixed month="DECEMBER" day="26" descriptionPropertiesKey="STEPHENS"/>

        <tns:ChristianHoliday type="EASTER" chronology="JULIAN"/>

        <tns:ChristianHoliday type="CLEAN_MONDAY"

            chronology="JULIAN" />

        <tns:ChristianHoliday type="GOOD_FRIDAY"

            chronology="JULIAN" />

        <tns:ChristianHoliday type="EASTER_MONDAY"

            chronology="JULIAN" />

        <tns:ChristianHoliday type="WHIT_MONDAY"

            chronology="JULIAN" />

    </tns:Holidays>

</tns:Configuration>

items
Switch TestEphemeris “Test Switch”

rules

  val filename = "Ephemeris"

rule "Ephemeris started rule"
when 

 Item TestEphemeris changed
then
   
   if (Ephemeris.isBankHoliday(0,"/etc/openhab2/services/Holidays_gr.xml") ) {
      logInfo(filename,"February 25") // not working
   }
   if ( Ephemeris.isBankHoliday(1,"/etc/openhab2/services/Holidays_gr.xml") ) {
      logInfo(filename,"February 26") //  not working
   }
   if (!isWeekend(5)) {
	logInfo(filename,"Ημέρα της εβδομάδας") // OK
   }
   if (isWeekend(4)) {
	logInfo(filename,"Αύριο είναι το Σαββατοκύριακο")  // OK
   }
   if (isInDayset("school",0))// deytera me paraskeuh 
   {
	logInfo(filename,"Υπάρχει σχολείο σήμερα") // OK 
   }

end

i’m trying


but not work
thanks

I also tried to use

isBankHoliday(1, "/etc/openhab2/services/myPlan.xml")

and ran into the same problem. Alternatively I tried to switch to

import java.time.ZonedDateTime; 
isBankHoliday(ZonedDateTime.now().plusDays(1), "/etc/openhab2/services/myPlan.xml")

Bit this always returns null and seams also not to work. Does anybody has a hint what could be wrong?

Thanks in advance,
Felix

Try

var datetime = new DateTimeType().zonedDateTime.now().plusDays(1)
if (Ephemeris.isBankHoliday(datetime, "/etc/openhab2/services/myPlan.xml") == true) {
   ...
}

Greetings
Roland

Hi Roland,

thanks for your help. Also seams not to work…

    val datetime = new DateTimeType().zonedDateTime.now().plusDays(1)
    val isHoliday = isBankHoliday(datetime, "/etc/openhab2/services/myPlan.xml")
    logInfo("ephemerisRules", isHoliday)

results in the error

An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

I will try to investigate some more,
Greetings,
Felix

I’m not fully sure about the difference between “val” and “var”, but I think that the DateTimeType is not a value but a variable…
So you may try to use “var” here.

You must convert your value to string when adding to log, for example this way:

logInfo("ephemerisRules", "Is holiday: " + isHoliday)

Use val if the variable doesn’t need a change
Use var if the variable will change

val myVariable = 1
myVariable = 2     // will give an error

var myVariable2 = 1
myVariable2 = 2  // will work