Datetime ambiguous feature

I have a DSL rules “annoyance”, it is possibly a limitation of the VSCode extension or LSP.

I’m trying to get the last day of a calendar month in a rule, as an integer.
The real thing -

val maxDay = now.minusMonths(1).dayOfMonth.withMaximumValue.getDayOfMonth

VSCode complains about (underlines in red) the dayOfMonth method (property?), with text

Ambiguous feature call.
The methods
dayOfMonth() in DateTime and
getDayOfMonth() in AbstractDateTime
both match.

It does actually work, but it’s annoying for VSCode to flag an error in my rules file.

The simple self-contained example

var maxDayy = new DateTime().dayOfMonth

produces the same grumble.
Tried a few things, but it’s beaten me.

Oh wow, no sooner posted than stumbled on a fix
Use brackets.

var maxDay = startDate.dayOfMonth().withMaximumValue.getDayOfMonth

I’m happy with that, but if any knowledgeable types want to contribute a “why?” it would be appreciated :crazy_face:

Here’s something else that you could use without LSP tripping up…

import java.time.temporal.TemporalAdjusters
val maxDay = (new DateTimeType).zonedDateTime.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth).getDayOfMonth

And this one will work in OH 3.0 :wink:!

I’m told DSL rules will be forbidden in OH3 anyway :wink:

Temporal Adjusters sounds like an agency of the Timelord High Council.

1 Like

Still TBD… but just in case, here’s how it could be done in Jython…

from java.time.temporal import TemporalAdjusters

max_day = DateTimeType().zonedDateTime.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth()