0

I'm starting to write a small program involving holiday dates and had a question of opinion on my approach.

I am doing a check and if it aligns with one of the holiday dates then a decision is made. The holidays are always the same ones, Ala 4th of July, Thanksgiving, Labor day.

I could either put these dates for the next 10 years in a file, or figure them out programmatically each time and do the check date?

Which option do you guys think is best?

I would appreciate some feedback and opinions on this.

roeygol
  • 4,908
  • 9
  • 51
  • 88
Tastybrownies
  • 897
  • 3
  • 23
  • 49
  • 1
    Doing it programmatically is best – The Coding Monk Sep 13 '15 at 20:55
  • 1
    You can't do all of them programmatically. Some of them are decided by government only a year in advance. Others have wacky rules like "first x of the month y, except when ..." You should provide a way to edit/add them. – bvdb Sep 13 '15 at 21:10

3 Answers3

1

A combination of both:

  • if a date is not in the file then you should generate it and use it, while also adding it to the file
  • if the date is in the file, you just use it.
user3452075
  • 411
  • 1
  • 6
  • 17
1

If the holidays are always on the same date such as 4th of July, 5th of October and so on, you could just use the day-of-the-year to do your operation. I.e.

for (int i = 0; i < allMyHolidays.length; i++)
{
checkDayOfYear();
checkIfLeapYear();

   if (any of the specific holiday days are == true)
   {
    //make decision
   }
}

There is already a question on leap year calculations, answers include libraries that you can use as well: Java Code for calculating Leap Year

Community
  • 1
  • 1
marts
  • 658
  • 1
  • 10
  • 15
0

As I see it, the best way is to build a minimum DB which contains a table that contains these holidays you mentioned.

roeygol
  • 4,908
  • 9
  • 51
  • 88