svendiedrichsen / jollyday

Jollyday - A holiday API
Other
190 stars 114 forks source link

Get exhaustive set of holidays for country #131

Closed vbrandl closed 4 years ago

vbrandl commented 4 years ago

Is there a way to exhaustively check if a day is a holiday in any of the sub hierarchies of a calendar?

I'm trying to load all sub calendars and pass the set.toArray() as args to the isHoliday method:

private static Set<String> loadSubCalendars(CalendarHierarchy hierarchy) {
  final var result = new HashSet<String>(20);
  hierarchy
      .getChildren()
      .entrySet()
      .stream()
      .forEach(
          entry -> {
            result.add(entry.getKey());
            result.addAll(loadSubCalendars(entry.getValue()));
          });
  return result;
}

This does not seem to work. I could try to generate every possible hierarchy path and check for every path if a date is a holiday but this seems overkill...

If there is no feasible way to do this, is there a way to get a calendar that simply checks every available holiday independent of country or region?

svendiedrichsen commented 4 years ago

@vbrandl You are using the keys as is. But you need to use them as a path segment and add the structure up to the current point. Imagine the calendar for germany having a structure like

de -> hh
   -> sh

The list of structure lists to check would be [[de],[de,hh],[de,sh]].