Skip to main content

Calculation code comments Scrutiny start date for treaty periods A and B

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

1 module Calculations
2   module Backwards
3     module Treaty

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 set out in the Constitutional Reform and Governance Act 2010 section 20 paragraphs 2, 5 and 9.

9       def treaty_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.

13         date = target_end_date.next

We set the day count to zero.

16         day_count = 0

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

19         while day_count < target_day_count

... we move back to the previous day.

22           date = date.prev_day

If the day is a joint sitting day ...

25           if date.is_joint_parliamentary_sitting_day?

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

28             unless @scrutiny_end_date

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

31               @scrutiny_end_date = date
32             end

We add 1 to the day count.

35             day_count +=1

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

38           elsif date.is_calendar_not_populated?

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

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

44             break
45           end
46         end

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

49         date
50       end
51     end
52   end
53 end