I need the sunrise- and sunsettime of the astro binding in a number variable with the format “minutes of a day”. For example sunrise is at 7:30 the content of my number variable has to be: 450.
My question is now, is there any possibility to convert, for example the hours an minutes of a DateTime item into Number variables in a rule file?
Pseudo-Code of what i want to do:
var Number hours = MyDateTimeItem.gethours
var Number minutes = MyDateTimeItem.getminutes
content of MyDateTimeItem: 18:30 Uhr
content of hours: 18
content of minutes: 30
I have not tested this, but maybe you could do something like the following:
var Number minutesSinceMidnight = ( MyDateTimeItem.calendar.millis / (60 * 1000) )
Unfortunately it does not work, i get the following error:
2017-02-09 13:30:37.239 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'testregel': The name '<XFeatureCallImplCustom>.calendar' cannot be resolved to an item or type.
Do i have to include some special file?
I only have included:
I’ve got it working with this
var DateTime sonnenaufgang = new DateTime((I_BR_AS_SO_aufgang.state as DateTimeType).calendar.timeInMillis)
var DateTime sonnenuntergang = new DateTime((I_BR_AS_SO_untergang.state as DateTimeType).calendar.timeInMillis)
var Integer sonnenaufgang_min = sonnenaufgang.getMinuteOfDay
var Integer sonnenuntergang_min = sonnenuntergang.getMinuteOfDay
P.S. It is working without includes
OK, now it WORKS!!
BUT: @der-brumm-baer i have to include:
Thank you for your help guys!!
So you are on 1.8.3 or 2.x ?
Im on 1.8.3, sorry i have forgotten to tell.