Calculation code comments Scrutiny start date for bicameral instruments with both Houses sitting
On GitHub: app/lib/calculations/backwards/bicameral_both_houses_sitting.rb
1 module Calculations
2 module Backwards
3 module BicameralBothHousesSitting
This method deals with the case where days are not counted if either House is adjourned for more than four days.
This method is used for:
- made affirmative Statutory Instruments as set out in their enabling Act, for example: paragraph 9 of section 5 of the National Insurance Contributions Act 2014
- Legislative Reform Orders as set out in sections 18 and 19 of the Legislative and Regulatory Reform Act 2006
- Public Body Orders as set out in paragraph 12 of section 11 of the Public Bodies Act 2011
- Localism Orders as set out in paragraph 14 of section 19 of the Localism Act 2011
- published drafts as set out in paragraph 14 of schedule 8 of the European Union (Withdrawal) Act 2018
- enhanced affirmatives under the Investigatory Powers Act 2016 as set out in paragraph 11 of section 268 of the Investigatory Powers Act 2016
14 def bicameral_calculation_both_houses_sitting_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.
18 date = target_end_date.next
We set the day count to zero.
21 day_count = 0
Whilst the number of days we’re counting is less than the target number of days to count ...
24 while day_count < target_day_count
... we move back to the previous day.
27 date = date.prev_day
If the day is a joint scrutiny day ...
30 if date.is_joint_scrutiny_day?
... if we've not set the scrutiny end date ...
33 unless @scrutiny_end_date
... we set the scrutiny end date to this date.
36 @scrutiny_end_date = date
37 end
We add 1 to the day count.
40 day_count += 1
Otherwise, if the calendar has no record of what type of day this is, we can't calculate the end date, ...
43 elsif date.is_calendar_not_populated?
... this error message is displayed to users ...
46 @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.
49 break
50 end
51 end
We return the anticipated start date of the scrutiny period for display.
54 date
55 end
56 end
57 end
58 end