Skip to main content

Calculation code comments Scrutiny start date for Commons only statutory instruments

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

1 module Calculations
2   module Backwards
3     module CommonsOnlySi

This method is used for:

  • Commons only negative Statutory Instruments as set out by the Statutory Instruments Act 1946
  • Commons only made affirmative Statutory Instruments as set out by their enabling Act

The calculation is set out in paragraphs 1 and 2 of Section 7 of the Statutory Instruments Act 1946.

A different calculation may be required if the instrument is laid under another Act - as set out in paragraph 3.

11       def commons_only_si_calculation_backwards( target_end_date, target_day_count )

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.

15         date = target_end_date.next

We set the day count to zero.

18         day_count = 0

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

21         while day_count < target_day_count

... we move back to the previous day.

24           date = date.prev_day

If the day is a Commons scrutiny day ...

27           if date.is_commons_scrutiny_day?

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

30             unless @scrutiny_end_date

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

33               @scrutiny_end_date = date
34             end

We add 1 to the day count.

37             day_count += 1

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

40           elsif date.is_calendar_not_populated?

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

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

46             break
47           end
48         end

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

51         date
52       end
53     end
54   end
55 end