• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need an open source tool for date calculation (US Holidays, Weekends)

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Masters,

I have a requirement where I have to manage date Calculation in US locale. Basically I have to add some days to the current date and addition does not consider public holidays and weekends.

For example, I have to add 3 days to my current date and today is Thursday. So I have to add three days to current day (Thursday) excluding weekends. So, I have to consider Friday, Monday and Tuesday for my calculation (excluding Saturday, Sunday).

Kindly let me know any open source tool is available for this functionality. If not, any clue/example which will help me.

Thanks in Advance.
Rakesh
 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rakesh,

Take a look at Joda Time.

-- Srikkanth
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is wrong with the date/time API in Java8? That is based on Joda Time and will probably do everything you want.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell,

I should admit that I have not familiarized myself with Java 8 Date API changes : ) Thanks for pointing it out.

Thanks
Srikkanth
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java®8 date API is completely different from the old classes like Calendar and Date. They are even immutable now

But they won't work on Java7.
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Srikkanth and Campbell.

We are using Java 6 and will not be able to upgrade to Java 8.

I will try with Joda Time and let you know.

Regards,
Rakesh
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joda Time it is, then. But why can you not upgrade?
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are slight differences between JodaTime and the new Java 8 API. Each one is better in some aspects and worse in others, sadly.

However, neither of them, as far as I know, has a built in support for handling public holidays and working/nonworking days. Uncle Google might help: java business calendar. Some libraries did pop up in the search, but I didn't have a closer look.

In one of our projects, I've implemented a business calendar myself, but I only needed things like nextBusinessDay(), prevBusinessDay() and isBusinessDay(), which are relatively straightforward. Doing more complicated operations could use some external library.
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Joda Time it is, then. But why can you not upgrade?



Campbll, I am working for a project which is using a commerce framework, which needs Java 6 and cannot upgrade Java because of this.

Thanks,
Rakesh
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:There are slight differences between JodaTime and the new Java 8 API. Each one is better in some aspects and worse in others, sadly.

However, neither of them, as far as I know, has a built in support for handling public holidays and working/nonworking days. Uncle Google might help: java business calendar. Some libraries did pop up in the search, but I didn't have a closer look.

In one of our projects, I've implemented a business calendar myself, but I only needed things like nextBusinessDay(), prevBusinessDay() and isBusinessDay(), which are relatively straightforward. Doing more complicated operations could use some external library.



Thanks Martin, for the info. Let me do some googling. Will post here if I am getting some updates on this.

Thanks,
Rakesh
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:There are slight differences between JodaTime and the new Java 8 API. Each one is better in some aspects and worse in others, sadly.

However, neither of them, as far as I know, has a built in support for handling public holidays and working/nonworking days. Uncle Google might help: java business calendar. Some libraries did pop up in the search, but I didn't have a closer look.

In one of our projects, I've implemented a business calendar myself, but I only needed things like nextBusinessDay(), prevBusinessDay() and isBusinessDay(), which are relatively straightforward. Doing more complicated operations could use some external library.



Also Martin, I think from your impleentation, isBusinessDay() may help me . I can add one day to current day, I can check isBusinessDay(), if false, I wont consider that day and go to next day and do the same logic (Assuming isBusinessDay() will consider public holidays and weekends. Is my assumption correct?

Thanks,
Rakesh
 
Martin Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the late reply.

There isn't anything special about isBusinessDay. It might be just a list of all exact holiday dates covering the period you're processing, or it might contain rules to generate holidays based on their definitions. Holidays may be fixed (they fall on given day of month every year), in which case I keep the day, month, first year of observance and last year of observance, or they may be moving. In my country, Easter Monday is the only moving holiday. I'm using the Computus algorithm to find the occurrence of Easter in a given year.
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Martin Vajsar wrote:Sorry for the late reply.

There isn't anything special about isBusinessDay. It might be just a list of all exact holiday dates covering the period you're processing, or it might contain rules to generate holidays based on their definitions. Holidays may be fixed (they fall on given day of month every year), in which case I keep the day, month, first year of observance and last year of observance, or they may be moving. In my country, Easter Monday is the only moving holiday. I'm using the Computus algorithm to find the occurrence of Easter in a given year.



Thanks Martin!
 
reply
    Bookmark Topic Watch Topic
  • New Topic