I’m creating a UI that allows the user the select a date range, and tick or un-tick the days of the week that apply within the date range.
The date range controls are DateTimePickers, and the Days of the Week are CheckBoxes
Here’s a mock-up of the UI:
From Date: (dtpDateFrom)
To Date: (dtpDateTo)
[y] Monday, [n] Tuesday, [y] Wednesday, (etc)
What’s the best way to show a total count the number of days, based not only on the date range, but the ticked (or selected) days of the week?
Is looping through the date range my only option?
Here’s how I would approach it:
As pseudo code:
This will take constant time, no matter how far apart the start and end days.
The details of implementing this algorithm depend on what language and libraries you are using. Where possible, I use C++ plus boost::date_time for this sort of thing.