Calculation code comments Scrutiny start date for Commons only sitting days
On GitHub: app/lib/calculations/commons_only_sitting_days_reverse.rb
1 module Calculations
2 module CommonsOnlySittingDaysReverse
The calculation counts a day whenever the House of Commons has an actual sitting day - and requires the start date and the number of days to count.
The calculation is set out in section 5 (4A) of the Planning Act 2008.
8 def commons_only_sitting_days_reverse( date, target_day_count )
We set the scrutiny start date, being the start date of the calculation and the end date of the scrutiny period.
11 @scrutiny_start_date = nil
We go forward one day.
14 date = date.next
We set the day count to zero.
17 day_count = 0
Whilst the number of days we’re counting is less than the target number of days to count ...
20 while ( day_count < target_day_count ) do
... continue to the previous day.
23 date = date.prev_day
If the date is actual sitting day in the House of Commons ...
26 if date.is_commons_actual_sitting_day?
... we set the scrutiny start date to this date if the scrutiny start date is nil ...
29 @scrutiny_start_date = date if @scrutiny_start_date.nil?
... and add 1 to the day count.
32 day_count +=1
Otherwise, if the calendar has no record of what type of day this is, we can't calculate the end date, ...
35 elsif date.is_calendar_not_populated?
... this error message is displayed to users ...
38 @error_message = "It's not currently possible to calculate an anticipated start date, as that date occurs during a period for which no sitting day information is available."
... and we stop looking through the calendar.
41 break
42 end
43 end
We return the calculated date.
46 date
47 end
48 end
49 end