Skip to main content

Calculation code comments Scrutiny start date for proposed negative statutory instruments

On GitHub: app/lib/calculations/backwards/pnsi.rb

1 module Calculations
2   module Backwards
3     module Pnsi

The calculation is set out in the European Union (Withdrawal) Act 2018 schedule 7 paragraph 17(10) (number of days to count) and paragraph 17(11) (definition of sitting day).

The same calculation is also set out in:

10       def pnsi_calculation_backwards( target_end_date, target_day_count )

PNSIs are considered by both Houses, so we'll get ready to start counting the sitting days in each House.

13       	commons_day_count = 0
14         lords_day_count = 0

Because the start of each loop causes the date to move to the preceding day and we wish to include the target end date ...

... we go forward one day.

18         date = target_end_date.next

The total day count is 10 days of which:

  • the last nine sitting days are counted when each House is sitting. Both Houses must have sat for nine days, but these do not need to be joint sitting days.
  • the first day is counted when both Houses are sitting - a joint sitting day.

We subtract one from the target day count in order to count to nine sitting days in each House.

25         target_day_count = target_day_count - 1

Whilst the Commons day count is less than the target day count or the Lords day count is less than the target day count ...

28         while ( ( commons_day_count < target_day_count ) or (lords_day_count < target_day_count ) )

... we move back to the previous day.

31           date = date.prev_day

If this is a sitting day in either House...

34           if date.is_either_house_parliamentary_sitting_day?

... if we've not set the scrutiny end date ...

37             unless @scrutiny_end_date

... we set the scrutiny end date to this date.

40               @scrutiny_end_date = date
41             end

If this is a sitting day in the Lords ...

44             if date.is_lords_parliamentary_sitting_day?

... we add a day to the Lords’ count

47               lords_day_count +=1
48             end

If this is a sitting day in the Commons ...

51             if date.is_commons_parliamentary_sitting_day?

... we add a day to the Commons’ count

54               commons_day_count +=1
55             end
56           end

If the calendar has no record of what type of day this is, we can't calculate the start date, ...

59           if date.is_calendar_not_populated?

... this error message is displayed to users ...

62             @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.

65             break
66           end
67         end

We've now counted nine sitting days in both the Commons and the Lords.

The first day of the scrutiny period must be a joint sitting day, as set out in paragraph 17 (10) (a) of the European Union (Withdrawal) Act 2018 ...

... so we find the last joint sitting day preceding the date we've counted to.

72         date.last_joint_parliamentary_sitting_day

We return the anticipated start date of the scrutiny period for display.

75         date
76       end
77     end
78   end
79 end