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:
Emi Matchu 2024-06-20 14:08:40 -07:00
parent 965725f9e9
commit b137eed4c4

View file

@ -80,9 +80,15 @@ class Item
# NOTE: This could return strange results if the Owls date contains
# something surprising! But the heuristic nature helps with e.g.
# flexibility if they abbreviate months, so let's lean into `Date.parse`.
match => {month:, day:}
date = Date.parse("#{month} #{day}, #{Date.today.year}")
date += 1.year if date < Date.today - 3.months
begin
match => {month:, day:}
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
end