Oops, fix silly bug in Dyeworks Owls date parsing

Oh right, if I assume "date in the past means it's for next year", then
that means that, when the date *does pass*, we won't realize it!

e.g. if Owls says "Dyeable Thru July 15", then on July 14 we'll parse
that as July 15, 2024; but on July 16 we'll parse it as July 16, 2025,
and so we'll think it's *still* dyeable. Under this logic, it's
actually impossible for a limited Dyeworks date to *ever* be in the
past, I think!

I think 3 months is a good compromise: it gives Owls plenty of time to
update, but allows for events that could last as long as 9 months into
the future, if I'm doing my math right.
This commit is contained in:
Emi Matchu 2024-06-20 14:04:45 -07:00
parent 341a8dd89c
commit 965725f9e9

View file

@ -70,15 +70,19 @@ class Item
match(DYEWORKS_LIMITED_FINAL_DATE_PATTERN) match(DYEWORKS_LIMITED_FINAL_DATE_PATTERN)
return nil if match.nil? return nil if match.nil?
# Parse this "<Month> <Day>" date as the *next* such date: parse it as # Parse this "<Month> <Day>" date as the *next* such date, with some
# this year at first, then add a year if it turns out to be in the past. # wiggle room for the possibility that it recently passed and Owls hasn't
# updated yet: parse it as this year at first, then add a year if that
# turns out to be more than 3 months ago. (That way, if it's currently
# December 2024, then events ending in Jan will be read as Jan 2025, and
# events ending in Nov will be read as Nov 2024.)
# #
# 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:} match => {month:, day:}
date = Date.parse("#{month} #{day}, #{Date.today.year}") date = Date.parse("#{month} #{day}, #{Date.today.year}")
date += 1.year if date < Date.today date += 1.year if date < Date.today - 3.months
date date
end end