Skip to main content

Calculation code comments Scrutiny start date for Commons only statutory instruments

On GitHub: app/lib/calculations/commons_only_si_reverse.rb

1 module Calculations
2   module CommonsOnlySiReverse

The calculation counts in actual sitting days, requiring the start date and the number of days to count.

The calculation is defined by paragraphs 1 and 2 of Section 7 of the Statutory Instruments Act 1946, though a different calculation may be required if the instrument is laid under another Act - as per paragraph 3.

7     def commons_only_si_calculation_reverse(date, target_day_count)

We start counting on the first day the House of Commons has a scrutiny day.

For negative Statutory Instruments this will be the day on which the instrument was laid, if that day was a scrutiny day. For made negative Statutory Instruments, this is defined by the Statutory Instruments Act 1946 Section 5 paragraph 1. For draft negative Statutory Instruments, this is defined by the Statutory Instruments Act 1946 Section 6 paragraph 1.

For made affirmatives this will be the day on which the instrument was made, if that day was a scrutiny day.

We set the scrutiny start date, being the start date of the calculation and the end date of the scrutiny period.

13       @scrutiny_start_date = nil

We go forward one day.

16       date = date.next

We set the day count to zero.

19       day_count = 0

Whilst the number of days we’re counting is less than the target number of days to count ...

22       while day_count < target_day_count

... continue to the previous day.

25         date = date.prev_day

If the day is a Commons scrutiny day ...

28         if date.is_commons_scrutiny_day?

... we set the scrutiny start date to this date if the scrutiny start date is nil ...

31           @scrutiny_start_date = date if @scrutiny_start_date.nil?

... and add 1 to the day count.

34           day_count += 1

Otherwise, if the calendar has no record of what type of day this is, we can't calculate the end date, ...

37         elsif date.is_calendar_not_populated?

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

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

43           break
44         end
45       end

Return the anticipated end date of the scrutiny period for display.

48       date
49     end
50   end
51 end