Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPEALS-51555 (BUG): Hearing Time Options Not Reflecting Persisted Values #22184

Merged
merged 16 commits into from
Jul 18, 2024
8 changes: 5 additions & 3 deletions app/repositories/hearing_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions app/services/hearing_time_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions config/initializers/timezone.rb
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -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"] })
Expand Down
11 changes: 8 additions & 3 deletions spec/controllers/hearings_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand All @@ -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}"
)
Expand Down
2 changes: 1 addition & 1 deletion spec/feature/intake/issue_modification_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/repositories/hearing_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -54,10 +54,10 @@
RequestStore.store[:current_user] = create(:user, vacols_uniq_id: staff_record.slogid)
end

it "slots hearing at correct time" do

Check failure on line 57 in spec/repositories/hearing_repository_spec.rb

View workflow job for this annotation

GitHub Actions / caseflow_rspec_job (12, 11)

HearingRepository.slot_new_hearing slots hearing at correct time Failure/Error: expect(VACOLS::CaseHearing.find_by(vdkey: hearing_day.id) .hearing_date.to_datetime.in_time_zone("UTC").hour).to eq(9) expected: 9 got: 8 (compared using ==)
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)
Expand Down
19 changes: 10 additions & 9 deletions spec/services/hearing_time_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
Loading