That is the absolutely most important thing to achieve in your code. Take pity on future Rey and make your code easy to understand. 
Why not do it the same way you did with fruehestens
and use withHour
and withMinute
? Then you don’t need to import and use LocalTime (that’s probably one of your errors, you’re missing Java.type("java.time.LocalTime");
)
Personally, I find it easier to follow when the code almost reads like prose and calling withX
does that better than using with
.
However, you have an error in fruegestens
. When you call plusX
or even with
that doesn’t change the ZonedDateTime, it returns a new ZonedDateTime with the change applied. So:
var offset_sec = 0;
var offset_min = 0;
var offset_hr = 0;
var fruehestens = sonnenuntergang.plusSeconds(offest_sec);
fruehestens = fruehestens.plusMinutes(offset_min);
fruehestens = fruehestens.plusHours(offset_hr);
That’s why you often see them all combined on the same line.
var fruehestens = sonnenuntergang.plusSeconds(offest_sec)
.plusMinutes(offset_min)
.plusHours(offest_hr);
It avoids repeated assignments to the same variable. Also note that just because it’s one line of code doesn’t mean it has to be all on one line of the text. Personally, I find it easier to follow if the offset variables are removed too. It’s pretty self explanatory to just put the numbers in the function calls instead of creating a single use variable.
So doing it the same way with spaetestens
var spaetestens_hr = 23;
var spaetestens_min = 30;
var spaetestens = ZonedDateTime.now(); // NOTE: you have a type here, two "nn" but only one "n" everywhere else
spaetestens = spaetestens.withHour(spaetestens_hr);
spaetestens = spaetestens.withMinute(spaetestens_min);
Or more compressed:
var spaetestens_hr = 23;
var spaetestens_min = 30;
var spaetestenns = ZonedDateTime.now()
.withHour(spaetestens_hr)
.withMinute(spaetestens_min);
and without the variables
var spaetestenns = ZonedDateTime.now()
.withHour(23)
.withMinute(30);
One other note. You have a syntax error in your code above. You defined spaetestenns
but then try to use spaetestens
. That will generate an error in the logs. When working on a rule, always look in the logs. When asking for help, always post the relevant logs. The logs are vital to understand what is going on when your code runs. You should have seen an error when running the above along the lines of “undefined doesn’t have a function with”.