chronic
chronic copied to clipboard
last day of the month
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.
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.
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.
That is what I ended up doing for that particular case instead of usng Chronic.
@jeremywadsack Yeah that was my intention for this. Just haven't found time to get around to it yet.
It would also be great to have "Last Monday in May" logic (this is US Memorial Day).
+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
+1 for last weekday of month
+1 last day of the month
+1 last day of the month
+1 last day of the month
+1
Here is how I did it based on @jeremywadsack's comment:
Chronic.parse('1st day next month') - 1.day
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