jueves, febrero 25, 2010

Time waits for nobody

Yesterday I discovered a new library based on Joda Time and JDK 5 Time, called DateCalc (objectlabkit) http://objectlabkit.sourceforge.net/

This library is useful when our application must deal with holidays and what to do when a calculated day falls on a holiday or weekend.

Imagine next use case:
- Employees have to say how many days of vacation will enjoy from one date. System must notify when employees are at office.

Assume that employee says that he will start his vacations on 22/02/2010 and will be 6 days out of office. So in theory our employee will be at office on 28th day of same month (22 + 6). But looking at calendar, one will see that he won't be there on 28 because it is Sunday (assuming that weekends are Saturday and Sunday). In fact he will be at office on 1/03/2010 (Monday).

This use case can be focused with two approaches:

1) Using java.util.Calendar class, and then the holidays and weekends problem must be controlled by our program. Calculating “what day our employee returns to office” is not only a matter of calling Calendar.add function.

2) Using DateCalc library which watch out for us.

Not only think about weekends and summer holidays, but national holidays like 4th of July in case of USA.

Take a look to its website, there you can find examples and algorithms for handling holiday problem