Calculation code comments Scrutiny start date for treaty periods A and B
On GitHub: app/lib/calculations/treaty_reverse.rb
1 module Calculations
2 module TreatyReverse
The calculation counts a day whenever both Houses have an actual sitting day - and requires the start date and the number of days to count.
For period A the start date is the day on which "a Minister of the Crown has laid before Parliament a copy of the treaty".
For period B the start date is the day on which "a Minister of the Crown has laid before Parliament a statement indicating that the Minister is of the opinion that the treaty should nevertheless be ratified and explaining why".
The calculation is defined by Constitutional Reform and Governance Act 2010 section 20 paragraphs 2, 5 and 9.
10 def treaty_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 ) do
... continue to the previous day.
25 date = date.prev_day
If the day is a joint actual sitting day ...
28 if date.is_joint_actual_sitting_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
We return the calculated date.
48 date
49 end
50 end
51 end