Skip to content

Commit

Permalink
warn on invalid publication date, fixes #98
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Jan 27, 2025
1 parent b67868a commit 46002b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/relaton_bib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity,
def format_date(date, format, str, outformat = nil)
date = Date.strptime(date, format)
str ? date.strftime(outformat || format) : date
rescue Date::Error => e
Util.warn "#{date} #{e.message}"
date
end

# @param arr [nil, Array, #is_a?]
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_bib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonBib
VERSION = "1.20.3".freeze
VERSION = "1.20.4".freeze
end
6 changes: 6 additions & 0 deletions spec/relaton_bib_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
expect(RelatonBib.parse_date("2012-2")).to eq "2012-02"
expect(RelatonBib.parse_date("2012-2", false)).to eq Date.new(2012, 2, 1)
end

it "invalid date" do
expect do
expect(RelatonBib.parse_date("2012-02-31")).to eq "2012-02-31"
end.to output(/invalid date/).to_stderr_from_any_process
end
end

it "parse YAML with an old version of Psych" do
Expand Down

0 comments on commit 46002b0

Please sign in to comment.