Calculation code comments Scrutiny end date for Commons only sitting days
On GitHub: app/lib/calculations/forwards/commons_only_sitting_days.rb
1 module Calculations
2 module Forwards
3 module CommonsOnlySittingDays
The calculation is set out in section 5 (4A) of the Planning Act 2008.
The NPS calculation begins on "the first sitting day after the day on which the statement is laid before Parliament".
8 def commons_only_sitting_days_forwards( date, target_day_count )
We set the day count to zero.
11 day_count = 0
While the number of days we’ve counted is less than the target number of days to count ...
14 while ( day_count < target_day_count )
... we continue to the next day.
17 date = date.next_day
If the day is a Commons sitting day ...
20 if date.is_commons_parliamentary_sitting_day?
... if we've not set the scrutiny start date ...
23 unless @scrutiny_start_date
... we set the scrutiny start date to this date.
26 @scrutiny_start_date = date
27 end
We add one to the day count.
30 day_count += 1
31 end
If the calendar has no record of what type of day this is, we can't calculate the end date, ...
34 if date.is_calendar_not_populated?
... this error message is displayed to users ...
37 @error_message = "It's not currently possible to calculate an anticipated end date, as the likely end date occurs during a period for which sitting days are yet to be announced."
... and we stop looking through the calendar.
40 break
41 end
42 end
We return the anticipated end date of the scrutiny period for display.
45 date
46 end
47 end
48 end
49 end