Calculation code comments Scrutiny start date for proposed negative statutory instruments
On GitHub: app/lib/calculations/pnsi_reverse.rb
1 module Calculations
2 module PnsiReverse
The calculation counts in parliamentary sitting days, requiring the laying date and the number of days to count.
The calculation is defined by the European Union (Withdrawal) Act 2018 schedule 7 paragraph 17(10) (number of days to count) and paragraph 17(11) (definition of sitting day).
7 def pnsi_calculation_reverse( date, target_day_count )
PNSIs are always before both Houses, so we'll get ready to start counting the sitting days in each House.
The first joint sitting day counts as day 1 in both Houses, so we count from 1 rather than from 0.
11 commons_day_count = 0
12 lords_day_count = 0
We set the scrutiny start date, being the start date of the calculation and the end date of the scrutiny period.
15 @scrutiny_start_date = nil
We go forward one day.
18 date = date.next
We look at preceding days, ensuring that we've counted at least nine parliamentary sitting days in each House.
The total day count in each House must be 10 days and the first day of scrutiny must be a joint sitting day.
We'll handle the first day of scrutiny later.
For now, we take the target count of 10 days and remove one day, that being the joint sitting day.
24 until ( ( commons_day_count >= target_day_count - 1 ) and ( lords_day_count >= target_day_count - 1 ) ) do
... continue to the previous day.
27 date = date.prev_day
PNSIs use parliamentary sitting days, rather than naive sitting days.
If this is a parliamentary sitting day in either House...
31 if date.is_either_house_parliamentary_sitting_day?
... we set the scrutiny start date to this date if the scrutiny start date is nil ...
34 @scrutiny_start_date = date if @scrutiny_start_date.nil?
If the Lords sat on the date we've found, we add a day to the Lords’ count.
37 lords_day_count +=1 if date.is_lords_parliamentary_sitting_day?
If the Commons sat on the date we've found, we add a day to the Commons’ count.
40 commons_day_count+=1 if date.is_commons_parliamentary_sitting_day?
41 end
If the calendar has no record of what type of day this is, we can't calculate the end date, ...
44 if date.is_calendar_not_populated?
... this error message is displayed to users ...
47 @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.
50 break
51 end
52 end
We've now counted 10 sitting days in each House.
According to paragraph 17 (10) (a) of the European Union (Withdrawal) Act 2018, the first day of the scrutiny period must be a joint sitting day.
We find the last joint sitting day preceding the date we've counted to.
57 date.last_joint_parliamentary_sitting_day
We return the anticipated start date of the scrutiny period for display.
60 date
61 end
62 end
63 end