diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index ed0fdf839..4df769fc0 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -44,4 +44,16 @@ module CollectionTimeHelper def previous_collection_start_date current_collection_start_date - 1.year end + + def currently_crossover_period? + # generally the crossover period ends on the first Friday in June, but there may be arbitrary exceptions such as in 2023 + today = Time.zone.today + if today.year == 2023 + today.between?(Time.zone.local(2023, 4, 1).to_date, Time.zone.local(2023, 6, 9).to_date) + else + crossover_end_date = Time.zone.local(today.year, 6, 1).to_date + crossover_end_date += 1 until crossover_end_date.friday? + today.between?(Time.zone.local(today.year, 4, 1).to_date, crossover_end_date) + end + end end diff --git a/spec/helpers/collection_time_helper_spec.rb b/spec/helpers/collection_time_helper_spec.rb index 1537926ab..dad456e34 100644 --- a/spec/helpers/collection_time_helper_spec.rb +++ b/spec/helpers/collection_time_helper_spec.rb @@ -109,4 +109,64 @@ RSpec.describe CollectionTimeHelper do end end end + + describe "#currently_crossover_period?", focus: true do + subject(:result) { currently_crossover_period? } + + around do |example| + Timecop.freeze(now) do + example.run + end + end + + context "when it is January" do + let(:now) { Time.utc(2022, 1, 3) } + + it "returns false" do + expect(result).to be false + end + end + + context "when it is December" do + let(:now) { Time.utc(2020, 12, 3) } + + it "returns false" do + expect(result).to be false + end + end + + context "when it is April" do + let(:now) { Time.utc(2023, 4, 3) } + + it "returns true" do + expect(result).to be true + end + end + + context "when it is June" do + context "and it is the first Friday" do + let(:now) { Time.utc(2024, 6, 7) } + + it "returns true" do + expect(result).to be true + end + end + + context "and it is after the first Friday" do + let(:now) { Time.utc(2024, 6, 8) } + + it "returns false" do + expect(result).to be false + end + end + + context "and it is 2023, after the first Friday, but before the arbitrary crossover period end" do + let(:now) { Time.utc(2023, 6, 7) } + + it "returns true" do + expect(result).to be true + end + end + end + end end