Holidays - is there a java implementation?

JavaDate

Java Problem Overview


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?)

Java Solutions


Solution 1 - Java

I have written the Jollyday API and I'm interested to know what is so 'rough' about it. How can I improve it? Would be great to hear from you. Send me an email to [email protected] if you like.

By the way. Jollyday is used just the way as the questioner requests it. Please look for yourself.

Cheers, Sven

P.S.: I found a free webservice from Ulrich Hilger which provides detailed worldwide holiday info. Look at api.daybase.eu

Solution 2 - Java

Nothing robust exist in Java as far as I know. It also makes sense, this kind of information is namely extremely sensitive to changes. Hardcoding it would make your code potentially break on every Java update which may lead to lot of maintenance and compatibility troubles. Currently at hightest the timezones are hardcoded/maintained in Java SE and even alone that has already lead to many bugs.

Rather use a public webservice for that. E.g. http://www.bank-holidays.com

> This site informs you of all the days when banks (as well as stock exchange & school holidays in a number of countries) are closed due to religious or public events. Major events (elections, announced strikes, trade fairs, festivals, sports events...) are also listed. > > Our FREE SERVICE allows you to view the current calendar year (view only). For 2 euros/country/year, our PAY SERVICE (click on credit card icon) gives you access to calendar years 2000-2070.

And write a Java wrapper around that. Or look for existing Java API's which are in turn already backed by a webservice.

Solution 3 - Java

I also wrote a java wrapper around the Ruby Holidays Gem (. It's available on Github: https://github.com/gdepourtales/holidays. It works similar to Jollyday (http://sourceforge.net/projects/jollyday/).

Solution 4 - Java

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. ;)

Solution 5 - Java

My searching has brought up two results (in addition to what I listed in the comments). The first, the Holiday Client API, seems to be a dead project. The second, Jollyday, looks like a very rough, but active, work in progress.

As for why there is no good library, I'm with Tom. I suspect that your premise "Surely there are lots of properly based rules for the holidays in 99% of the times" is incorrect.

Solution 6 - Java

I think you'll have to do the work yourself.

National holidays are determined by, well, nations. They can change, and are, by definition, not universal, and can thus not be captured by some algorithm.

The only way to keep track of them, is to maintain them on a per-nation basis.

Perhaps someone actually already does that (maybe a webservice of sorts), but I doubt it, to be honest.

Solution 7 - Java

So far I haven seen any. But what I could suggest for u is to try to link with google calendar api, which from there try to get the holiday calendar through the calendar feed or whatever u call it. From there, process the data and if u want, save it into your database. Afterall, as long as you have a active internet connection, you can use java to connect to the relevant data Even for other languages, I dont think that such direct methods are available.

Solution 8 - Java

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"
	},
    ...
]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEspen SchulstadView Question on Stackoverflow
Solution 1 - JavaSvenView Answer on Stackoverflow
Solution 2 - JavaBalusCView Answer on Stackoverflow
Solution 3 - JavaGuyView Answer on Stackoverflow
Solution 4 - JavaAshok M AView Answer on Stackoverflow
Solution 5 - JavaPopsView Answer on Stackoverflow
Solution 6 - JavaWillem van RumptView Answer on Stackoverflow
Solution 7 - JavaC_RanceView Answer on Stackoverflow
Solution 8 - JavaTino HagerView Answer on Stackoverflow