use jode in rules or scripts

108 views
Skip to first unread message

helmut....@ingenieurbuero-mbi.de

unread,
Apr 5, 2014, 12:44:32 PM4/5/14
to ope...@googlegroups.com
Hi all,

the following is perhaps a noob question. It this is the case, just give me the right hint, and I´m sorry.

I´d like to use a joda-time calculation/API access to get the current time for the UTC timezone, to calculate sunrise and sundown independent from summertime (daytime saving time).
So I have to get the current time in a way like this :

var check = now.withZone(DateTimeZone.UTC)

jode-time API docs state, that UTC timezone is defined as a field, so this should be correct, but designer marks it as error and the rule engine throws errors, too :

Message: Error during the execution of rule Set Sun and Dawn States
java.lang.RuntimeException: The name 'DateTimeZone' cannot be resolved to an item or type.
    at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:67)
    at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateAbstractFeatureCall(XbaseInterpreter.java:658)
    at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)


Obvious and understandable, I have to import the required parts of joda-time, but I do not find any suitable jar to include within openhab files, the assumed

import org.joda.time.DateTimeZone

didn´t solve this issue.

So, my question is, how could this be done. I didn´t find any documentation with regard to joda-time together with openhab, just a pull request for updating joda to ver 2.3, so i assume it should be there and also it should be available to scripts; or is there only a subset without timezone support available within openHAB ?

Thanks for your time and your help

cheers,

Flipper

Kai Kreuzer

unread,
Apr 5, 2014, 4:23:15 PM4/5/14
to ope...@googlegroups.com
Hi,

You almost have it right. You indeed need the import

import org.joda.time.DateTimeZone

and then you need to use double colons as you are doing a static reference. So your variable definition has to be

var check = now.withZone(DateTimeZone::UTC)

Hope this helps!
Kai
--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

helmut....@ingenieurbuero-mbi.de

unread,
Apr 5, 2014, 7:03:38 PM4/5/14
to ope...@googlegroups.com

Hi Kai,

thank you for the help, what you told me did the trick !

I think I´ll have to read much more...

Cheers, Flipper

Reply all
Reply to author
Forward
0 new messages