1 module CALCULATION_TREATY

A method for calculating the end date for treaty periods A and B.

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.

 9   def treaty_calculation( date, target_day_count )

We start counting on the first day when both Houses have an actual sitting.

For period A this does not include the laying day of the treaty.

For period B this does not include the day on which a Minister makes a statement that the treaty should nevertheless be ratified.

We continue to the day immediately following the start day.

If that day is or is followed by a joint actual sitting day...

 17     if date.next_day.first_joint_actual_sitting_day

... we set the date to the day of the first joint actual sitting day following the start date.

 20       date = date.next_day.first_joint_actual_sitting_day

... we have found the start of the scrutiny period.

 23       @scrutiny_start_date = date

... we've found the first joint actual sitting day so we start counting from day 1.

 26       day_count = 1

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

 29       while ( day_count < target_day_count ) do

... continue to the next day.

 32         date = date.next_day

... and add 1 to the day count if this is an joint actual sitting day.

 35         day_count +=1 if date.is_joint_actual_sitting_day?

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

 38         if date.is_calendar_not_populated?

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

 41           @error_message = "It's not currently possible to calculate an anticipated end date, as the likely end date occurs during a period for which sitting days are yet to be announced."

... and we stop looking through the calendar.

 44           break
 45         end
 46       end

If day immediately following the laying day is not a joint actual sitting day and is not followed by a joint actual sitting day...

 49     else

.. this error message is displayed to users.

 52       @error_message = "Unable to find a future joint sitting day. It's not currently possible to calculate an anticipated end date, as the likely end date occurs during a period for which sitting days are yet to be announced."
 53     end

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

 56     date
 57   end
 58 end