From 6cb2ae3d76eca7e5e88142598e6b331850342673 Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Tue, 4 Oct 2022 13:55:36 +0200 Subject: [PATCH 1/2] Add rspec test for fractional date --- .../datacite-example-fractional-date.xml | 23 +++++++++++++++++++ spec/readers/datacite_reader_spec.rb | 8 +++++++ 2 files changed, 31 insertions(+) create mode 100644 spec/fixtures/datacite-example-fractional-date.xml diff --git a/spec/fixtures/datacite-example-fractional-date.xml b/spec/fixtures/datacite-example-fractional-date.xml new file mode 100644 index 00000000..e57411f3 --- /dev/null +++ b/spec/fixtures/datacite-example-fractional-date.xml @@ -0,0 +1,23 @@ + + + 10.5072/example-fractional-date + + + Claire L O?Brien + + + + Impact of Colonoscopy Bowel Preparation on Intestinal Microbiota + + + 2020-11-06T21:37:33.12Z + + The Australian National University Data Commons + 2013 + + + + en + + diff --git a/spec/readers/datacite_reader_spec.rb b/spec/readers/datacite_reader_spec.rb index fc1ff294..2f75fa35 100644 --- a/spec/readers/datacite_reader_spec.rb +++ b/spec/readers/datacite_reader_spec.rb @@ -1653,4 +1653,12 @@ ) end + it "Parses dates with fractional seconds" do + input = fixture_path + "datacite-example-fractional-date.xml" + subject = Bolognese::Metadata.new(input: input) + expect(subject.valid?).to be true + expect(subject.dates).to eq([{"date"=>"2020-11-06T21:37:33.12Z", "dateType"=>"Updated"}, {"date"=>"2013", "dateType"=>"Issued"}]) + end + + end From 670523d8038d7b926b7f4ffc8cd08dac5d39e86e Mon Sep 17 00:00:00 2001 From: Bryceson Laing Date: Fri, 14 Oct 2022 10:45:14 -0700 Subject: [PATCH 2/2] Fixed the fractional date issue --- lib/bolognese/readers/datacite_reader.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/bolognese/readers/datacite_reader.rb b/lib/bolognese/readers/datacite_reader.rb index e9dfc430..7a029c21 100644 --- a/lib/bolognese/readers/datacite_reader.rb +++ b/lib/bolognese/readers/datacite_reader.rb @@ -125,11 +125,15 @@ def read_datacite(string: nil, **options) dates = Array.wrap(meta.dig("dates", "date")).map do |r| if r.is_a?(Hash) && date = sanitize(r["__content__"]).presence - if Date.edtf(date).present? || Bolognese::Utils::UNKNOWN_INFORMATION.key?(date) - { "date" => date, - "dateType" => parse_attributes(r, content: "dateType"), - "dateInformation" => parse_attributes(r, content: "dateInformation") - }.compact + begin + if Date.edtf(date).present? || Bolognese::Utils::UNKNOWN_INFORMATION.key?(date) || Time.iso8601(date).present? + { "date" => date, + "dateType" => parse_attributes(r, content: "dateType"), + "dateInformation" => parse_attributes(r, content: "dateInformation") + }.compact + end + rescue + nil end end end.compact