Tastybrownies
Tastybrownies

Reputation: 937

Better to Use Text File or Program for Dates

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.

Upvotes: 0

Views: 74

Answers (3)

marts
marts

Reputation: 678

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

Upvotes: 1

user3452075
user3452075

Reputation: 461

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.

Upvotes: 1

roeygol
roeygol

Reputation: 5028

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

Upvotes: 0

Related Questions