Search code examples
javadatecalendartimestampdayofweek

Java weekend calculator API / Library


Lets say I have 2 dates in milliseconds or java.sql.Timestamp:

1342162320 <->  Fri Jul 13 2012 09:52:00 GMT+0300 (FLE Daylight Time)
1343162320 <-> Tue Jul 24 2012 23:38:40 GMT+0300 (FLE Daylight Time)

Lets say I provide these 2 dates, and I need:

Return int, if the time between JUL 13 09:52 - JUL 24 23:58 falls on weekends or big holidays, and if so, how many days.

I thought about just going through all dates, and checking if it is saturday or sunday, but maybe some more clever APIs?

I also looked into Joda library, but it does not specifically have these methods, just has some simplified JDK ones. Joda does not have holiday recognition.


Solution

  • You can use defined holiday calendars from http://www.calendarlabs.com/ical-calendar-holidays.php, they are available for a number of countries. It's format is called iCal, used by MS Outlook. It shouldn't be to hard to write a parser for that format. Then you have the 'red' dates and don't have to define and update, just download a new definition for every year.

    It might also be possible to get the holidays from Google Calendars or similar.