Calculation code comments Sitting days during an interval
On GitHub: app/lib/calculations/interval.rb
1 module Calculations
2 module Interval
The method is passed the start and end dates entered by the user.
The calculation is inclusive of the start and end dates.
7 def calculate_sitting_days_in_interval( start_date, end_date )
We set the date to start counting from the start date.
10 date = start_date
Whilst the date is not later than the end date ...
13 while date <= end_date
... if the calendar has no record of what type of day this is, we can't calculate the the number of sitting days, ...
16 if date.is_calendar_not_populated?
... this error message is displayed to users ...
19 @error_message = "It is not currently possible to calculate the number of sitting days, because the interval includes days for which the calendar is not populated."
... and we stop looking through the calendar.
22 break
Otherwise, if the calendar does have a record of what type of day this is ...
25 else
... if the date is a sitting day in the Commons ...
28 if date.is_commons_parliamentary_sitting_day?
... we increment the Commons sitting day count.
31 @commons_sitting_day_count += 1
32 end
If the date is a sitting day in the Lords ...
35 if date.is_lords_parliamentary_sitting_day?
... we increment the Lords sitting day count.
38 @lords_sitting_day_count += 1
39 end
We continue to the next day.
42 date = date.next_day
43 end
44 end
45 end
46 end
47 end