mojombo / chronic

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

Incorrect "month" date for Feb when it is a leap year #326

Open codered opened 8 years ago

codered commented 8 years ago

The month function should return the last day of the month, however, for leap years (this year), the last day of the month being returned is 2/28 instead of 2/29.

2.2.2 :032 > Chronic.parse("friday")
 => 2016-02-26 12:00:00 -0800
2.2.2 :033 > Chronic.parse("monday")
 => 2016-02-29 12:00:00 -0800
2.2.2 :034 > Chronic.parse("month")
 => 2016-02-28 00:00:00 -0800
2.2.2 :035 > Date.today.end_of_month
 => Mon, 29 Feb 2016
davispuh commented 8 years ago

why month should return end of month? it's actually not supported and that it returns anything at all is just pure luck.

for now you can use

Chronic.parse("1 day before next month", :guess => :begin)
=> 2016-02-29 00:00:00 +0200
SagareGanesh commented 8 years ago

@codered This issue is not only for Feb, I also have the same issue for August.

2.1.0 :021 > Chronic.parse("today") => 2016-08-23 21:00:00 +0530 2.1.0 :023 > Date.today.end_of_month => Wed, 31 Aug 2016 2.1.0 :022 > Chronic.parse("month") => 2016-08-28 00:00:00 +0530

Also year function gives me an unexpected result.

2.1.0 :024 > Chronic.parse("year") => 2016-10-28 00:00:00 +0530