Calculation code comments Scrutiny start date for bicameral instruments with either House sitting
On GitHub: app/lib/calculations/bicameral_si_either_house_sitting_reverse.rb
1 module Calculations
2 module BicameralSiEitherHouseSittingReverse
This method is used for bicameral negative Statutory Instruments as set out by the Statutory Instruments Act 1946 and for made affirmative Statutory Instruments as set out by their enabling Act.
The calculation is set out in paragraph 1 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.
This method is also used for calculations of scrutiny periods for proposed draft remedial orders and draft affirmative remedial orders and for scrutiny and approval periods for made affirmative remedial orders as set out in Schedule 2 of the Human Rights Act 1998.
The calculation counts in actual sitting days, requiring the start date and the number of days to count.
10 def bicameral_si_either_house_sitting_calculation_reverse( date, target_day_count )
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
... we continue to the previous day.
25 date = date.prev_day
If the day is a scrutiny day in either House ...
28 if date.is_either_house_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 start date of the scrutiny period for display.
48 date
49 end
50 end
51 end