svendiedrichsen / jollyday

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

How to check for regional holidays? #54

Closed wideocean closed 6 years ago

wideocean commented 6 years ago

As of now, I'm using the latest version (0.5.2).

Consider the following method which checks if the given date is a holiday:

public boolean isBankHoliday(Date d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d);
    URL url = getClass().getResource("/holidays/Holidays_de.xml");
    UrlManagerParameter urlManParam = new UrlManagerParameter(url, new Properties());
    HolidayManager holidayManager = HolidayManager.getInstance(urlManParam);

    boolean isHoliday = holidayManager.isHoliday(c, "de", "he");
    boolean isHolidayBundesland = holidayManager.isHoliday(c, "country.description.de.he");
    if (isHoliday || isHolidayBundesland) {
        return true;
    } else {
        return false;
    }
}

public static void main(){
    scanner = new Scanner(System.in);
    System.out.println("Enter the folder name: ");
    String input = scanner.next();
    DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
    Date date = format.parse(input);
    System.out.println(app.isBankHoliday(date));
}

The method is working fine for national-wide holidays (like New Year's etc.). However, if I try to check for holidays for let's say "Hessen" ("he"), then it seems to not working. I use the provided XML file and for "Hessen", there is an entry for the Christian holiday "CORPUS CHRISTI" which is the 31st May in 2018.

<tns:SubConfigurations hierarchy="he" description="Hesse">
    <tns:Holidays>
        <tns:ChristianHoliday type="CORPUS_CHRISTI" />
    </tns:Holidays>
</tns:SubConfigurations>

It returns false. Is .isHoliday(c, "de", "he") the correct usage here? How is the correct usage?

I appreciate every answer. Thank you.

wideocean commented 6 years ago

Sorry, I had a misunderstanding of the code usage. You need to look which hierarchy you want and then use the corresponding country code. If I want "Hessen", I can call .isHoliday(c, "he"). I was too confused by the code usage example with New York and New York City.

Can be closed.