64

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

Martin
  • 37,119
  • 15
  • 73
  • 82
Espen Schulstad
  • 2,355
  • 3
  • 21
  • 32
  • 2
    This may be useful to you: http://www.javaworld.com/javaworld/javatips/jw-javatip44.html?page=1 It's not a nicely wrapped JAR file, or I'd have made this a comment instead of an answer, but there is quite a bit of sample code on the last two pages. – Pops Aug 02 '10 at 14:30
  • 3
    As far as I know most (local at least) holidays get decided some years before, but are not necessarily based on static rules with lots of exceptions and possible adjustments. – poke Aug 02 '10 at 14:31
  • 4
    Isn't going to be that simple. Holidays change within regions. Canada has different holidays in its states. Scotland has different holidays from England & Wales. What is meant by a holiday differs. Even timezones are sometimes only decided upon weeks before. I'm sure some countries are in the habit of declaring holidays on the basis of immediate politics. – Tom Hawtin - tackline Aug 02 '10 at 14:36
  • 1
    Similar but not dupe: http://stackoverflow.com/questions/1044921/a-good-business-calendar-library-in-java – Pops Aug 02 '10 at 14:36
  • (IIRC, a few years ago the UK parliament change the date of a public holiday. Turns out the calendar and diary printers didn't read Hansard carefully, and had to pulp their products because of the wrong date.) – Tom Hawtin - tackline Aug 02 '10 at 14:41
  • Ok, how would you be able to update your database if a country adds a new national holiday? – Buhake Sindi Aug 02 '10 at 14:47
  • If you are using holiday to determine if that day is a work day, it's good to note that some holiday like "Canada Day" are not a work day for all the province of Canada except in Quebec where most people work on that day. – HoLyVieR Aug 02 '10 at 14:51
  • I guess we will continue our maintainance. I think I will just make a website where you can register your countries dates and an ability for the public to verify the legitimacy of the dates. Should be able to generate enough people to keep it up to date. Suggestion to downloadble formats? – Espen Schulstad Aug 02 '10 at 14:59
  • So you want to create another public webservice? :) For humans, CSV is the best choice. Fast to generate (sequentially) and easily importable in any decent DB and spreadsheet. I would rather provide an ability to alter the output format based on request parameter or pathinfo so that you can end up providing at least CSV, JSON and XML. JSON has the advantage that you can then access it directly programmatically from inside JavaScript/jQuery/etc. XML has the advantage that there are a lot of transformer tools for it in all programming languages. – BalusC Aug 02 '10 at 16:53

8 Answers8

18

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 sdiedrichsen@yahoo.de 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

Sven
  • 181
  • 3
  • 2
    you should include a link to jollyday – Nathan Feger Aug 23 '10 at 19:14
  • Does Jollyday allow adhoc public holidays to be defined? In the UK we had a holiday because of a royal wedding in 2011 and the Queen's Diamond Jubilee in 2012. These holidays only happen here and there, so Jollyday would need to be flexible enough to cater for this. Ideally, without a need of restarting a system. – mrswadge Apr 21 '15 at 14:47
14

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 3
    Impressive. Did a quick check, and they found everything for the Netherlands (my country). Including the one celebrated once every five years. – Willem van Rumpt Aug 02 '10 at 14:49
  • This looks like the only way to go. Of course this is still not universal in that some places might have other Holidays in addition or instead. I work for a large US company and they simply give an extra 10 floating personal days, this is more PC, since not everybody might want Christmas off. Some companies close between Christmas and New Years. – Romain Hippeau Aug 02 '10 at 14:51
5

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

Guy
  • 598
  • 5
  • 6
4

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

Community
  • 1
  • 1
Ashok M A
  • 478
  • 6
  • 14
2

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.

Pops
  • 30,199
  • 37
  • 136
  • 151
0

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.

Willem van Rumpt
  • 6,490
  • 2
  • 32
  • 44
  • 1
    Yes, this is what I'm fearing. Easiest would be if a store could be maintained yearly. Just have say 5 maintainers for the whole world, and the version number will be the year. – Espen Schulstad Aug 02 '10 at 14:38
0

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.

C_Rance
  • 661
  • 12
  • 25
0

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"
    },
    ...
]
Tino Hager
  • 898
  • 7
  • 23