I need to prevent entry to a car park system during public holidays, but instead of making more classes i was hoping it could be done within my existing method. my question is, is there such thing in java that already has public holiday dates predefined and can be used within if state or some sort to prevent entry if todays date matches those list of public holiday dates.

this is my existing method.which as you can see checks if its weekend, saturday and sunday, both which are public day off. but in uk there are more days such as bank holidays, but how do i define all the rest of the dates.

public boolean checkHoliday(){
        Calendar cal = Calendar.getInstance();
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); 
        if (dayOfWeek == 1 || dayOfWeek == 7){
            return true;
        } else {
            return false;
        }
         /*add method for further holiday date check*/ 


    }

Recommended Answers

All 7 Replies

there such thing in java that already has public holiday dates predefined

Public holidays are local. It would be necessary for Java to know where the code is being executed to determine if any day was a holiday.
I don't think you will find anything in Java that already has....

SwingX have got implemented excelent Java Calendar, there is simple workaround for Weekend and same way you can implements Special Days,

agreed with @NormR1 must be manually hardcoded/added to the File or Database

commented: Interesting, thanx for sharing +16

http://www.bank-holidays.com have a comprehensive database of world-wide public holidays. You get free access to view current info, but if this is a real app you can get the data in machine-readable form for a very reasonable price:

Receive your data in Excel format, with customized presentation, and including update alerts by e-mail for only 10 euros/country/calendar year

also: just speaking for my situation - the definition of 'public holiday' tends to adapt, not only where you are, but also, who you work for.
so, if you want to use your application just for yourself, my suggestion would be to use an excell file, which you can change easily.
if it's for a client, I would take a look at the site JamesCherrill mentioned. if it's supposed to work internationally though, you may want to leave the possibility for the client to make adaptations themselves.

@stultuske agreed (-: I checked link posted by @JamesCherrill, still there are differencies in compare with Hollydays for Currency and Secutities Trading from Reuters, I'm too lazy to check that in Bloomberg :-), now without any jokes, area with very important value, we have two responsible persons for this issue, per one from MiddleOffice and CorresponingBanking

Member Avatar for hfx642

I've just completed a module to do this exact function.
(Sorry... NOT for public consumption!)
You'll have to get a list of the days that YOU consider are special.
You'll have;
a) Specific Dates
b) Specific Days of Specific Weeks (watch for Victoria Day and Memorial Day)
c) Easter and all if it's related special days
d) Administrative Professions Day and Bosses Day are BOTH kind of tricky
You should be able to program the whole thing without using a year
or without using a big list of specific dates (MONTH DD YYYY).
Good Luck!

You can easily add a check to your method for user-defined public holidays, but you must define the holidays yourself. I would suggest adding a simple definition file that is loaded into memory when your program starts in case this method is called often.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.