[SOLVED] How to emulate an "Ephemeris.isHoliday()"?

Tags: #<Tag:0x00007f616f421300>


the standard


does not seem to return true for holidays that coincide with a weekend (well, banks, of course…). Easter Sunday is an example. How can I emulate something like


so I can check for a holiday even when it’s on a weekend? Plus, how can I get something like:


With a custom XML config that lists the weekend holidays. As you surmise, the default XML file from JollyDay does not include holidays that always occur on a weekend. But if you create your own XML you can list any day you want regardless of which day of the week it falls. See https://www.openhab.org/docs/configuration/actions.html#custom-bank-holidays for details.

Note that certain holidays like Easter are not easy to define without doing some calculations so those get defined differently. In the case of Easter I think you would use <tns:ChristianHoliday type="EASTER"/>.

1 Like

I have tried that, i.e. downloaded the xml-File and added the missing holidays. However in my case, I have added EASTER-MONDAY and if I use


I get the correct name, but when I use


I get false returned. Do I do something wrong?

1 Like

@glhopital, @cweitkamp, is this expected behavior where getBankHolidayName returns the name but isBankHoliday fails to return true?

Thank you - this is indeed a partial solution, I’ll comment further on Thomas’s reply.

There are some unpleasant inconsistencies, indeed. I’ve put Easter Sunday and Pentecost Sunday into my local copy of Holidays_de.xml:, to test @rlkoshak 's suggestion:

<tns:ChristianHoliday type="EASTER"/>
<tns:ChristianHoliday type="WHIT_SUNDAY"/>

and ran a few tests.

If I define
secondChristmasDay2021 = Ephemeris.getNextBankHoliday(622, "/etc/openhab2/services/Holidays_de.xml"), which happens to be a Sunday, where banks never work in Germany,

Ephemeris.isBankHoliday(622, "/etc/openhab2/services/Holidays_de.xml") returns 1, and
Ephemeris.getHolidayDescription(secondChristmasDay2021) returns “2. Weihnachtsfeiertag”.

If I define
pentecostSunday2021 = Ephemeris.getNextBankHoliday(405, "/etc/openhab2/services/Holidays_de.xml"), which is on a Sunday, too,

Ephemeris.isBankHoliday(405, "/etc/openhab2/services/Holidays_de.xml") returns 0, and
Ephemeris.getHolidayDescription(pentecostSunday2021) returns “Pfingsten”.

Strange inconsistencies:

  1. The Second Christmas Day of 2021 is considered to be a “bank holiday” although it’s on a Sunday (where banks would never be open in Germany, anyway).

  2. After having been added to the config file, Pentecost Sunday of 2021 is considered a bank holiday by getNextBankHoliday() (since it is returned as the next one), but not by isBankHoliday().

  3. Listing a holiday in Holidays_de.xml obviously only influences getNextBankHoliday(), but not isBankHoliday() - the information whether a holiday “is” a bank holiday seems to depend on other places in the code, too.

BTW: In Germany, we never speak of “bank holidays” but of “legal holidays” (which may differ a bit among our federal states). “Bank holiday” as a concept is not defined, over here. When Germans speak of “holidays” in general, they may have “legal holidays” in mind, but also holidays as defined by religious communities, which might not be “legal holidays” at all.

  1. isn’t that much of an inconsistency. The XML file that defines the holidays that comes with JollyDay only omits those holidays that always occur on a weekend. The second day of Christmas often can occur on a weekday so it’s included. They don’t update the XML file every year.

  2. That is the inconsistency identified by Thomas and which we need one of the feature devs to reply on. This could be expected behavior and they coded it that way (unlikely), expected behavior that the developer of JollyDay coded, or a bug that needs to be fixed.

  3. See 2.

We don’t in the US either. We have “Government holidays” which are days the government gives its employees off. But ultimately it is up to each employer to decide which (if any) holidays to give it’s employees. Many companies, especially those in the service sector, do not get any holidays at all. Even the schools often do not strictly follow the government holidays so the list that comes with JollyDay (and therefore is used by default by Ephemeris) is not all that useful for most of us in the US.

I think the term “Bank Holiday” mainly comes from the UK.

1 Like

Of course not. May I remind you on https://github.com/openhab/openhab-core/issues/1374. The getNextBankHoliday(<offset>, <file>) action is broken in OH 2.5.x. Please use getNextBankHoliday(<datetime>, <file>) instead by replacing <datetime> with ZonedDateTime.now().plusDays(<offset>).

1 Like

Right, but I thought that issue was that passing datetime was broken, not offset. I remembered it backwards.

Thanks to @rlkoshak, @CHTHSCH and @cweitkamp for their help.

To summarize a workaround for an isHoliday():

  1. Copy a locale-specific holiday list from the Jollyday repository, e.g. Holidays_de.xml

  2. Add missing holidays, e.g. <tns:ChristianHoliday type="EASTER"/>

  3. Store it in a suitable dir, e.g. the services config dir: /etc/openhab2/services/Holidays_de.xml

  4. To cope with a documented bug, use it with day offset to a ZonedDateTime, e.g. for tomorrow: Ephemeris.isBankHoliday(ZonedDateTime.now().plusDays(1), "/etc/openhab2/services/Holidays_de.xml")

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.