Hi,
I am struggling to come up with the logic to be able to find the amount to charge users for using a particular resource between a range of dates. I would appreciate very much if someone more experienced in C# could help me to find a solution and if possible provide some sample code.
I have two dates:
DateTime StartDateTime = 01/02/2014 22:00:00
DateTime EndDateTime = 28/02/2014 23:00:00
The booking of the resource will recur from the StartDateTime and EndDateTime. Based on the day of the week and the time of the day, I need to calculate how much of a resource will cost. 1 hours costs £10. However, I have to apply discounts depending on the day of the week and time of the day.
Example:
Monday to Friday from 8:00 till 17:00 - 15% discount
Monday to Friday from 17:00 to 00:00 10% discount
Saturday and Sunday 5% discount
This is the scenario:
If the user wants to use the resource on Monday, Wednesday, Friday and Sunday, I need to find out the following:
1 - all the Mondays, Wednesdays, Fridays and Sundays within the range of dates
2 - Apply the discount based on the rules above
3 - Add eveything to come up with a total to charge the user
Simple example:
To book the resource from 01/02/2014 22:00:00 to 01/02/2014 23:00:00
This will be only one day (Saturday) for only 1 hours.
Total = £10 - 5% = £9.50
But how can I calculate the total for a range of days within the date range?
Please remember this should work for any range of dates and leap years too
Cheers
CP