chronic icon indicating copy to clipboard operation
chronic copied to clipboard

last day of the month

Open rurounijones opened this issue 13 years ago • 13 comments

I am trying to find a way of getting the last day of a month, for example: last day of last month

I have tried various combos but cannot find anything. I have had a look through the code and it is a bit beyond me. Does anyone know if this can be done?

I should mention that the first day works. Something like "last month first day" or "first day of last month" is fine.

rurounijones avatar Dec 03 '10 03:12 rurounijones

There's currently no way of interpreting last as the end of a month. Chronic doesn't contain a month day lookup table except for when constructing Time objects, which is too low level for this. I've labeled this as a feature though, I think it's a great idea.

leejarvis avatar Jun 03 '11 20:06 leejarvis

How about last day of a month is first day of the next month minus one day? In other words, use the month day lookup that's built into ruby / the OS.

jeremywadsack avatar Mar 28 '12 21:03 jeremywadsack

That is what I ended up doing for that particular case instead of usng Chronic.

rurounijones avatar Mar 29 '12 00:03 rurounijones

@jeremywadsack Yeah that was my intention for this. Just haven't found time to get around to it yet.

leejarvis avatar Apr 02 '12 16:04 leejarvis

It would also be great to have "Last Monday in May" logic (this is US Memorial Day).

semperos avatar Jun 14 '12 17:06 semperos

+1 for last weekday of month. Currently doing this:

d = ((x = Chronic::parse("fifth Monday in May")).nil?) ? (Chronic::parse("fourth Monday in May)) : x

tamouse avatar Dec 01 '12 21:12 tamouse

+1 for last weekday of month

jaredbrown avatar Mar 26 '13 00:03 jaredbrown

+1 last day of the month

timfong888 avatar Oct 16 '15 18:10 timfong888

+1 last day of the month

kovpack avatar Apr 04 '16 07:04 kovpack

+1 last day of the month

shrav avatar Apr 22 '16 00:04 shrav

+1

zedtux avatar Feb 08 '17 18:02 zedtux

Here is how I did it based on @jeremywadsack's comment:

Chronic.parse('1st day next month') - 1.day

zedtux avatar Feb 08 '17 18:02 zedtux

This is a much needed feature... any ETA?

My use case: "Last day of next month"

Expected: If today is 14 Feb 2019 -> 31 March 2019

ghost avatar Feb 14 '19 15:02 ghost