Holidays - is there a java implementation?

Viewed 53042

I'd like to know if there is a jar-file out there that could do the following:

DateMidnight dateInQuestion = new DateMidnight(12,12,2000);
DateChecker.isNationalHoliday(dateInQuestion, Locale.ITALY);

If there isn't, why? Surely there are lots of properly based rules for the holidays in 99% of the times.

Right now we're mainting a table in our database, with the countries + we have some implementation when it comes to holidays that aren't on the same date every year. We have to add to our implementation for every new country we get new customers.

Could we do this an easier way?

(If there is no such thing in the java sphere, can I port it from some other language?)

8 Answers

I found this interesting:

RESTful service provider - Holiday API

For Node projects - node-holidayapi

I know it is not relevent to the question asked for Java implementation. But if your project is RESTful (like most of the projects nowadays) then this would give you a place to start. ;)

You can use my holiday api, there is also a docker container available to run the whole thing.

https://github.com/nager/Nager.Date

Webservice

Get the public holidays for Italy for the year 2000 https://date.nager.at/api/v2/PublicHolidays/2000/IT More information about the available API methods you can found here

Java Example

//https://github.com/FasterXML/jackson-databind/
ObjectMapper mapper = new ObjectMapper();
MyValue value = mapper.readValue(new URL("https://date.nager.at/api/v2/PublicHolidays/2000/IT"), PublicHoliday[].class);

PublicHoliday.class

public class PublicHoliday
{
    public String Date;
    public String LocalName;
    public String Name;
    public String CountryCode;
    public Boolean Fixed;
    public Boolean Global;
    public String[] Counties;
    public String Type;
}

Example JSON data retrieved

[
    {
        "date": "2000-01-01",
        "localName": "Capodanno",
        "name": "New Year's Day",
        "countryCode": "IT",
        "fixed": true,
        "global": true,
        "counties": null,
        "type": "Public"
    },
    ...
]
Related