diff --git a/app/services/open_bureau_date.rb b/app/services/open_bureau_date.rb index ba337ca3a..7b9e025a9 100644 --- a/app/services/open_bureau_date.rb +++ b/app/services/open_bureau_date.rb @@ -2,6 +2,16 @@ class OpenBureauDate include DateAndTime::Calculations def next_date + date = next_theoretical_date + + date = date.next_occurring(:tuesday).next_occurring(:tuesday) while cancelled_dates.include?(date) + + date + end + + private + + def next_theoretical_date return Time.zone.today if open_bureau_today? next_tuesday = Time.zone.today.next_occurring(:tuesday) @@ -11,7 +21,9 @@ def next_date next_tuesday.next_occurring(:tuesday) end - private + def cancelled_dates + YAML.load_file(Rails.root.join('config/cancelled_open_bureau_dates.yml')).map(&:to_date) + end def open_bureau_today? today = Time.zone.today diff --git a/config/cancelled_open_bureau_dates.yml b/config/cancelled_open_bureau_dates.yml new file mode 100644 index 000000000..cebd35423 --- /dev/null +++ b/config/cancelled_open_bureau_dates.yml @@ -0,0 +1,2 @@ +- '2024-11-19' +- '2024-12-3' diff --git a/spec/services/open_bureau_date_spec.rb b/spec/services/open_bureau_date_spec.rb index c38266639..274712c73 100644 --- a/spec/services/open_bureau_date_spec.rb +++ b/spec/services/open_bureau_date_spec.rb @@ -67,5 +67,16 @@ it { is_expected.to eq(next_date.to_s) } end end + + describe 'when it is a cancelled date' do + before do + Timecop.freeze(Date.new(2024, 11, 12)) + allow(YAML).to receive(:load_file).and_return(['2024-11-19']) + end + + let(:next_date) { Date.new(2024, 12, 3) } + + it { is_expected.to eq(next_date.to_s) } + end end end