Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum number of weekdays in a year? How would you code it?

In order to allocate enough space for an array element for each weekday of a year, I'm trying to work out the maximum number of rows I would need. That lead me onto the question of how I would work it out.

Would you have to calculate the number of days in every year for the next n years and go with that? Or is there (as I suspect) a more elegant solution involving the numbers 365, 366, 2 and 7?

Which libraries would help?

like image 470
Phil H Avatar asked Mar 27 '09 10:03

Phil H


1 Answers

The maximum number of days in a year is 366, this gives us 52 full weeks. In those 52 weeks there are at least 52 * 5 = 260 weekdays.

We are left with 2 days (52 * 7 = 364), it is possible that these 2 days are weekdays.

So maximum number of weekdays in a year is 262.

like image 98
GvS Avatar answered Oct 01 '22 08:10

GvS