mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.23k stars 452 forks source link

[Gem bug only] Parser handles missing years differently with numbers vs month names #397

Open agrberg opened 4 years ago

agrberg commented 4 years ago

Chronic will advance the year properly for a date that is past for the current year if given in mm/dd format but it will not for month_name dd.

# Let's make it 11/11/2020
now = Chronic.construct(2020, 11, 11) # => 2020-11-11 00:00:00 -0500
# The first of November is in the past for 2020 so both "Nov 1" and "11/1" should be 11/1/21
Chronic.parse("11/1", now: now)       # => 2021-11-01 12:00:00 -0400
# but it isn't with the month's name
Chronic.parse("Nov 1", now: now)      # => 2020-11-01 11:00:00 -0500

# It uses the current year as expected for the current date or a date in the future
Chronic.parse("11/11", now: now)  # => 2020-11-11 12:00:00 -0500
Chronic.parse("Nov 11", now: now) # => 2020-11-11 12:00:00 -0500
Chronic.parse("11/12", now: now)  # => 2020-11-12 12:00:00 -0500
Chronic.parse("Nov 12", now: now) # => 2020-11-12 12:00:00 -0500

A little bit of digging suggests the reason is that the day is not taken into account in RepeaterMonthName#next. Is this the correct behavior or am I'm missing something?

agrberg commented 4 years ago

This seems to be a problem on the latest release of the gem v 0.10.2. This is not the case on Master as it appears this line fixed it.