Can't use PeriodFormatter or PeriodFormatterBuilder

  • Platform information:
    • Hardware: Intel Atom x5, 4gb
    • OS: Windows 10
    • Java Runtime Environment: (Zulu 8.40.0.25-CA-win64) (build 1.8.0_222-b10)
    • openHAB version: 2.4.0

I don’t seem to be able to use PeriodFormatter or PeriodFormatterBuilder. My rule looks like this…

import org.joda.time.Duration
import org.joda.time.format.DateTimeFormat
import org.joda.time.format.DateTimeFormatter
import org.joda.time.format.PeriodFormatter
import org.joda.time.format.PeriodFormatterBuilder

rule "Test rule"
when
    Item Test_Switch1 received command 
then
    logInfo("[DEBUG]: ", Duration.name());
    logInfo("[DEBUG]: ", PeriodFormatter.name());
    logInfo("[DEBUG]: ", PeriodFormatterBuilder.name());
end 

When I trigger the rile, I get the following in the log:

2020-02-29 15:05:33.098 [INFO ] [pse.smarthome.model.script.[DEBUG]: ] - org.joda.time.Duration
2020-02-29 15:05:33.100 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test rule': The name 'PeriodFormatter' cannot be resolved to an item or type; line 12, column 26, length 15

I’m not all that experienced with java, so any help is appreciated.

Have you seen this?

And…

Note, that is going to look for a variable (or Item) called PeriodFormatter and try to get a name method on it.

Thanks @5iver Scott!

Yes, I did see both of those. Like i said, though I’ve been a coder for decades, I’m in the .net stack and not very familiar with things like "“maven” and “Jython”.

If I interpret all that correctly, I’ll need to use a version that’s newer than the stable build. I’m not entirely afraid of that, particularly since it seems i’ll get access to a more advanced rules engine. Even if it means I have to learn a new syntax, I’d like to have more “coder-friendly” scripting.

Thanks for answering!

Thanks @rossko57 !

I’m not up to speed on the nuances of this language. My rule was more complex that that; I just tried to shorten using down to something that looked simple and would throw the same error.

Thanks again for replying.

Nope… 2.5.2 will work fine. Scripted automation is perfect for a developer and Python is easy to learn. It’s night and day compared to the DSL. There’s no maven involved :slightly_smiling_face:, just scripting. Let me know if you need any help!