forked from OpenNeo/impress
Oops, handle date parsing errors in Dyeworks logic
Huh, I thought I'd tried some invalid dates and they gave me *surprising* output instead of raising an error. Well, maybe it can do both, depending on exactly the nature of the unexpected input? In any case, I found that a bad month name like "UwU" raised an error. So, let's catch it if so!
This commit is contained in:
parent
965725f9e9
commit
b137eed4c4
1 changed files with 9 additions and 3 deletions
|
@ -80,9 +80,15 @@ class Item
|
||||||
# NOTE: This could return strange results if the Owls date contains
|
# NOTE: This could return strange results if the Owls date contains
|
||||||
# something surprising! But the heuristic nature helps with e.g.
|
# something surprising! But the heuristic nature helps with e.g.
|
||||||
# flexibility if they abbreviate months, so let's lean into `Date.parse`.
|
# flexibility if they abbreviate months, so let's lean into `Date.parse`.
|
||||||
match => {month:, day:}
|
begin
|
||||||
date = Date.parse("#{month} #{day}, #{Date.today.year}")
|
match => {month:, day:}
|
||||||
date += 1.year if date < Date.today - 3.months
|
date = Date.parse("#{month} #{day}, #{Date.today.year}")
|
||||||
|
date += 1.year if date < Date.today - 3.months
|
||||||
|
rescue Date::Error
|
||||||
|
Rails.logger.warn "Could not parse Dyeworks final date: " +
|
||||||
|
"#{nc_trade_value.value_text.inspect}"
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
date
|
date
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue