Reputation: 937
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
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
Reputation: 461
A combination of both:
Upvotes: 1
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