From a142d6cecda1dbc0b72ec998af4ee08ce30c0f40 Mon Sep 17 00:00:00 2001 From: noahhansen-gov <166541737+noahhansen-gov@users.noreply.github.com> Date: Thu, 18 Jul 2024 07:43:05 -0600 Subject: [PATCH] APPEALS-51555 (BUG): Hearing Time Options Not Reflecting Persisted Values (#22184) * pushing up * cleaning up code * pushing up * pushing up * rubocopn * fixing rspec tests * fixing rspec tests * pushing tests * rubocop * Lint roll * Remove zero padding from times * Remove hardcoded tz * Test fixes * Fix expected error class * Fix unrelated failing test --------- Co-authored-by: nhansen3 Co-authored-by: Matthew Thornton <99351305+ThorntonMatthew@users.noreply.github.com> Co-authored-by: Matthew Thornton --- app/repositories/hearing_repository.rb | 8 +++++--- app/services/hearing_time_service.rb | 16 ++++++++++------ config/initializers/timezone.rb | 9 +++++++++ .../filled_hearing_slots_controller_spec.rb | 6 +++++- spec/controllers/hearings_controller_spec.rb | 11 ++++++++--- .../intake/issue_modification_request_spec.rb | 2 +- spec/repositories/hearing_repository_spec.rb | 4 ++-- spec/services/hearing_time_service_spec.rb | 19 ++++++++++--------- 8 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 config/initializers/timezone.rb diff --git a/app/repositories/hearing_repository.rb b/app/repositories/hearing_repository.rb index cb7449b3273..f909af19c36 100644 --- a/app/repositories/hearing_repository.rb +++ b/app/repositories/hearing_repository.rb @@ -38,15 +38,17 @@ def update_vacols_hearing!(vacols_record, hearing_hash) def fix_hearings_timezone(scheduled_time_string) time_str_split = scheduled_time_string.split(" ", 3) - tz_str = time_str_split[2] + + tz_str = ActiveSupport::TimeZone::MAPPING[time_str_split[2]] + tz_str = ActiveSupport::TimeZone::MAPPING.key(time_str_split[2]) if tz_str.nil? + begin - new_tz = ActiveSupport::TimeZone.find_tzinfo(tz_str) + ActiveSupport::TimeZone.find_tzinfo(tz_str).name rescue TZInfo::InvalidTimezoneIdentifier => error Raven.capture_exception(error) Rails.logger.info("#{error}: Invalid timezone #{tz_str} for hearing day") raise error end - new_tz.name end # rubocop:disable Metrics/MethodLength diff --git a/app/services/hearing_time_service.rb b/app/services/hearing_time_service.rb index 89065f29d10..ab792d32bdf 100644 --- a/app/services/hearing_time_service.rb +++ b/app/services/hearing_time_service.rb @@ -44,11 +44,12 @@ def legacy_formatted_scheduled_for(scheduled_for:, scheduled_time_string:) end end - def time_to_string(time) - return time if time.is_a?(String) - + def time_to_string(time, hearing) datetime = time.to_datetime - "#{pad_time(datetime.hour)}:#{pad_time(datetime.min)}" + + tz = ActiveSupport::TimeZone::MAPPING.key(hearing.regional_office_timezone) + + "#{datetime.strftime('%l:%M %p')} #{tz}".lstrip end def convert_scheduled_time_to_utc(time_string) @@ -59,6 +60,9 @@ def convert_scheduled_time_to_utc(time_string) # Generate the scheduled_time in UTC and update the scheduled_time_string scheduled_time = time_string[0..index].strip timezone = time_string[index..-1].strip + + ### This is hardcoded. We do not want this hardcoded in the future + timezone = ActiveSupport::TimeZone::MAPPING[timezone] return Time.use_zone(timezone) { Time.zone.parse(scheduled_time) }.utc end nil @@ -80,11 +84,11 @@ def initialize(hearing:) end def scheduled_time_string - self.class.time_to_string(local_time) + self.class.time_to_string(local_time, @hearing) end def central_office_time_string - self.class.time_to_string(central_office_time) + self.class.time_to_string(central_office_time, @hearing) end def local_time diff --git a/config/initializers/timezone.rb b/config/initializers/timezone.rb new file mode 100644 index 00000000000..92ad91f8cc2 --- /dev/null +++ b/config/initializers/timezone.rb @@ -0,0 +1,9 @@ +### ### +### merge our maintained mappings with the existing mappings in TimeZone +### Doesn't provide all timezones we need +### Add timezones to here for more timezone support +### ### +TIMEZONE_MAPPINGS = { + "Philippine Standard Time" => "Asia/Manila" +} +ActiveSupport::TimeZone.const_set(:MAPPING, ActiveSupport::TimeZone::MAPPING.merge(TIMEZONE_MAPPINGS)) diff --git a/spec/controllers/hearings/hearing_day/filled_hearing_slots_controller_spec.rb b/spec/controllers/hearings/hearing_day/filled_hearing_slots_controller_spec.rb index 2e04bbce0d6..60e59256c05 100644 --- a/spec/controllers/hearings/hearing_day/filled_hearing_slots_controller_spec.rb +++ b/spec/controllers/hearings/hearing_day/filled_hearing_slots_controller_spec.rb @@ -51,7 +51,11 @@ expect(response_body["filled_hearing_slots"].first.keys).to match_array(expected_keys) expect(response_body["filled_hearing_slots"].second.keys).to match_array(expected_keys) - slots = Time.zone.now.in_time_zone("America/New_York").zone == "EDT" ? ["09:30", "12:00"] : ["08:30", "12:00"] + slots = if Time.zone.now.in_time_zone("America/New_York").zone == "EDT" + ["9:30 AM Eastern Time (US & Canada)", "12:00 PM Eastern Time (US & Canada)"] + else + ["8:30 AM Eastern Time (US & Canada)", "12:00 PM Eastern Time (US & Canada)"] + end expect(response_body["filled_hearing_slots"].map { |res| res["hearing_time"] }) .to match_array(slots) expect(response_body["filled_hearing_slots"].map { |res| res["issue_count"] }) diff --git a/spec/controllers/hearings_controller_spec.rb b/spec/controllers/hearings_controller_spec.rb index 32d87e1d20d..0890f890e7c 100644 --- a/spec/controllers/hearings_controller_spec.rb +++ b/spec/controllers/hearings_controller_spec.rb @@ -519,8 +519,13 @@ let(:is_daylight_savings_on) { Time.zone.now.in_time_zone(expected_time_zone).zone == "EDT" } let!(:hearing) do - create(:hearing, :with_tasks, scheduled_time: is_daylight_savings_on ? "7:30 AM" : "8:30 AM", - scheduled_in_timezone: "Eastern Time (US & Canada)") + create( + :hearing, + :with_tasks, + scheduled_time: + is_daylight_savings_on ? "7:30 AM Eastern Time (US & Canada)" : "8:30 AM Eastern Time (US & Canada)", + scheduled_in_timezone: "Eastern Time (US & Canada)" + ) end subject { get :show, as: :json, params: { id: hearing.external_id } } @@ -534,7 +539,7 @@ body = JSON.parse(subject.body) expect(body["data"]["regional_office_timezone"]).to eq(expected_time_zone) - expect(body["data"]["scheduled_time_string"]).to eq(expected_time) + expect(body["data"]["scheduled_time_string"]).to eq("8:30 AM Eastern Time (US & Canada)") expect(body["data"]["scheduled_for"]).to eq( "#{hearing.hearing_day.scheduled_for}T#{expected_time}:00.000#{utc_offset}" ) diff --git a/spec/feature/intake/issue_modification_request_spec.rb b/spec/feature/intake/issue_modification_request_spec.rb index 5d2f143482e..94be10afe98 100644 --- a/spec/feature/intake/issue_modification_request_spec.rb +++ b/spec/feature/intake/issue_modification_request_spec.rb @@ -87,7 +87,7 @@ nonrating_issue_description: withdrawal_request_issue.nonrating_issue_description, decision_date: withdrawal_request_issue.decision_date, request_issue: withdrawal_request_issue, - withdrawal_date: Time.zone.now - 1.day) + withdrawal_date: (Time.zone.now - 1.day).beginning_of_day) end let!(:modify_existing_modification_request) do diff --git a/spec/repositories/hearing_repository_spec.rb b/spec/repositories/hearing_repository_spec.rb index 57b1f90f59e..5032355586a 100644 --- a/spec/repositories/hearing_repository_spec.rb +++ b/spec/repositories/hearing_repository_spec.rb @@ -41,7 +41,7 @@ it "throws an error if the timezone is invalid" do expect do HearingRepository.fix_hearings_timezone(invalid_tz) - end.to raise_error(TZInfo::InvalidTimezoneIdentifier) + end.to raise_error(TZInfo::UnknownTimezone) end end @@ -57,7 +57,7 @@ it "slots hearing at correct time" do HearingRepository.slot_new_hearing( hearing_day_id: hearing_day.id, - scheduled_time_string: "09:00 AM EST", + scheduled_time_string: "09:00 AM Eastern Time (US & Canada)", appeal: legacy_appeal ) expect(VACOLS::CaseHearing.find_by(vdkey: hearing_day.id) diff --git a/spec/services/hearing_time_service_spec.rb b/spec/services/hearing_time_service_spec.rb index cfd255bfc02..a82ac8eb5e2 100644 --- a/spec/services/hearing_time_service_spec.rb +++ b/spec/services/hearing_time_service_spec.rb @@ -24,18 +24,19 @@ describe "#build_params_with_time" do let!(:params) do - { scheduled_time_string: "13:30" } + { scheduled_time_string: "01:30 PM Pacific Time (US & Canada)" } end it "returns scheduled_time string parameter and removes scheduled_time_string param" do - expect(HearingTimeService.build_params_with_time(hearing, params)).to eq(scheduled_time: "13:30") - expect(params).to eq(scheduled_time_string: "13:30") + expect(HearingTimeService.build_params_with_time(hearing, params)) + .to eq(scheduled_time: "01:30 PM Pacific Time (US & Canada)") + expect(params).to eq(scheduled_time_string: "01:30 PM Pacific Time (US & Canada)") end end describe "#build_legacy_params_with_time" do let(:params) do - { scheduled_time_string: "13:30" } + { scheduled_time_string: "01:30 PM Eastern Time (US & Canada)" } end it "returns scheduled_for parameter in ET and removes scheduled_time_string param" do @@ -45,7 +46,7 @@ end expected_params = { scheduled_for: expected_scheduled_for } expect(HearingTimeService.build_legacy_params_with_time(legacy_hearing, params)).to eq(expected_params) - expect(params).to eq(scheduled_time_string: "13:30") + expect(params).to eq(scheduled_time_string: "01:30 PM Eastern Time (US & Canada)") end end @@ -68,8 +69,8 @@ describe "#scheduled_time_string" do it "converts time to local time in HH:mm string" do - expect(LegacyHearing.first.time.scheduled_time_string).to eq("12:00") - expect(hearing.time.scheduled_time_string).to eq("12:00") + expect(LegacyHearing.first.time.scheduled_time_string).to eq("12:00 PM Pacific Time (US & Canada)") + expect(hearing.time.scheduled_time_string).to eq("12:00 PM Pacific Time (US & Canada)") end end @@ -83,8 +84,8 @@ describe "#central_office_time_string" do it "changes to central office timezone (ET)" do - expect(hearing.time.central_office_time_string).to eq("15:00") - expect(LegacyHearing.first.time.central_office_time_string).to eq("15:00") + expect(hearing.time.central_office_time_string).to eq("3:00 PM Pacific Time (US & Canada)") + expect(LegacyHearing.first.time.central_office_time_string).to eq("3:00 PM Pacific Time (US & Canada)") end end