mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
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'
This commit is contained in:
parent
37a8f6cdd2
commit
289b04bc69
2 changed files with 14 additions and 4 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue