rossko57
(Rossko57)
March 13, 2020, 11:27pm
1
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.
rossko57
(Rossko57)
March 13, 2020, 11:31pm
2
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
5iver
(Scott Rushworth)
March 14, 2020, 5:07am
3
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 !
rossko57
(Rossko57)
March 14, 2020, 10:38am
4
I’m told DSL rules will be forbidden in OH3 anyway
Temporal Adjusters sounds like an agency of the Timelord High Council.
1 Like
5iver
(Scott Rushworth)
March 14, 2020, 3:22pm
5
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()