match an additional format for Dates. Supported dates are now '1/10/2022 14:21:45' '2022-1-10T14:21:45' '2022-1-10 14:21:45'

rpp-main
Nelson Jovel 2 years ago
parent fc2c52984c
commit 9bfb76db5a

@ -48,10 +48,12 @@ class SurveyItemValues
def recorded_date
@recorded_date ||= begin
recorded_date = value_from(pattern: /Recorded\s*Date/i)
date = if recorded_date.include?("T")
date = if recorded_date.match(%r{\d+/\d+/\d+\s+\d+:\d+:\d+})
Date.strptime(recorded_date, "%m/%d/%Y")
elsif recorded_date.match(/\d+-\d+-\d+(T|\s)\d+:\d+:\d+/)
Date.parse(recorded_date)
else
Date.strptime(recorded_date, "%m/%d/%Y")
puts "Recorded date in unknown format"
end
end
end

@ -833,7 +833,7 @@ RSpec.describe SurveyItemValues, type: :model do
create(:academic_year, range: "2021-22")
end
it "parses the date correctly when the date is in standard date format for google sheets" do
it "parses the date correctly when the date is in standard date format for google sheets: 'MM/DD/YYYY HH:MM:SS'" do
recorded_date = "1/10/2022 14:21:45"
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, survey_items:,
schools:)
@ -841,12 +841,20 @@ RSpec.describe SurveyItemValues, type: :model do
expect(values.academic_year).to eq ay_21_22
end
it "parses the date correctly when the date is in iso standard 8601" do
it "parses the date correctly when the date is in iso standard 8601 'YYYY-MM-DDTHH:MM:SS'" do
recorded_date = "2022-1-10T14:21:45"
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, survey_items:,
schools:)
ay_21_22 = AcademicYear.find_by_range "2021-22"
expect(values.academic_year).to eq ay_21_22
end
it "parses the date correctly when the date is in the format of: 'YYYY-MM-DD HH:MM:SS'" do
recorded_date = "2022-01-10 14:21:45"
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "DeseID" => "1234" }, headers:, survey_items:,
schools:)
ay_21_22 = AcademicYear.find_by_range "2021-22"
expect(values.academic_year).to eq ay_21_22
end
end
end

Loading…
Cancel
Save