Improve performance of AddWorkingDays algorithm
Hi There,
Firstly, thanks for the great library.
I know it is noted that the AddWorkingDays extension method is not designed to be used with large datasets. Is there any possibility of improving the performance of this method so that it can be run more efficiently?
I'm happy to have a go at this myself, my thoughts are to create a in-memory map of:
- The date component of the DateTime
- The integer of the number of days to add
- The resultant date
Then, each time the method is run, first check if the date-integer combination is in the map. If so, get the resultant date and add on the time component.
This method is making a few assumptions about how working days are calculated, so I'd like to hear your thoughts on this.
Adam
Hi,
Well, the worst part of the calculation is actually translate the working days, into calendar days. Is short, it's only your step2. That's because we need to skip holidays and weekends.
For this to work in a not iterative algorithm, we need to calculate the number of weekends, and holidays not weekends, in the time period.
Then subtract that value from the virtual end date (date as in just calculating calendar days = DateTime.AddDays(n)