This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to check a date as 'holiday' in java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to check a date as Watch "How to check a date as New topic
Author

How to check a date as 'holiday' in java

Biswajit Paria
Ranch Hand

Joined: Feb 02, 2003
Posts: 46
Hi,
Could you please tell me, how to check a Date as holiday?
i.e
for example today's date is 03/04/2006.
How do i make a check that today is holiday (excluding/including weekend, it's your choice! ).

Thanks,
Biswajit
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Java's GregorianCalendar class knows nothing about holidays, since thay are particular to a location, and subject to change. What you could do is create a static data structure containing all the dates which constitute a holiday in whichever location your application is being run (you will have to populate this manually) and check dates against it. For example you could have a HashMap for each year, keyed on Calendar.DAY_OF_YEAR, whose value is a Boolean denoting whether it is a holiday or not.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Biswajit Paria:
Hi,
Could you please tell me, how to check a Date as holiday?


You mean like Diwali?


There is no emoticon for what I am feeling!
Biswajit Paria
Ranch Hand

Joined: Feb 02, 2003
Posts: 46
Thanks Paul Sturrock for your nice suggestion.
In other ways, by creating a table in database with holidays list we can do the same thing.


Jeff Albertson ,
How do you want to feel..?


Thanks,
B
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Biswajit Paria:
In other ways, by creating a table in database with holidays list we can do the same thing.

Yes, but for speed you probably want this in memory. A database round trip every time you use a date is a bit of an overhead. If your application reads your table once when it starts up and hold the data in memory you avoid this.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by Biswajit Paria:
Jeff Albertson ,
How do you want to feel..?


Yaar, I want to feel that Java will be able to tell me when Diwali starts.
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
just found the perfect solution for your problem

here



jan
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to check a date as 'holiday' in java
 
Similar Threads
java.util.Date for any year
Code to check whether a given date falls on weekend or holidays
Code to check whether a given date falls on weekend or holidays
WA #1.....word association
display only 2 rows from a recordset size of 10