chronic icon indicating copy to clipboard operation
chronic copied to clipboard

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

Open codered opened this issue 10 years ago • 1 comments

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

codered avatar Feb 25 '16 22:02 codered

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

davispuh avatar Feb 26 '16 00:02 davispuh

@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

SagareGanesh avatar Aug 23 '16 12:08 SagareGanesh