Hmm ?! Maybe you have a look on this post. There are some examples.
I made a test with a similar rule. Here’s the snippet:
if(now.isBefore((Sunset_Time_Test.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)) { // https://community.openhab.org/t/solved-datetimetype-is-deprecated/37296/31
logInfo("Datum testen", "Line 70 - now {} is before {} ", now, Sunset_Time_Test.state as DateTimeType)
and the result in the logger:
2019-10-13 17:48:50.446 [INFO ] [.smarthome.model.script.Datum testen] - Line 70 - now 2019-10-13T17:48:50.445+02:00 is before 2019-10-13T21:10:00.000+0200
Corresponding item:
DateTime Sunset_Time_Test "Sonnenuntergang Test Start[%1$ta, %1$td.%1$tm.%1$ty, %1$tH:%1$tM]" <sunset> (gAstrotest) {channel="astro:sun:stowing1:set#start"}
So how does your item looks like ?
Here is the whole rule were I test such stuff. Maybe this can help you too:
var boolean log = true
rule "Datum testen"
when
Item Dummy4 changed to ON
then
var day_1 = new DateTime(localLastMeasurement_00.state.toString).toString("yyMMddHHmm")
var day_2 = new DateTime(localLastMeasurement_00.state.toString).plusDays(1).plusHours(6).toString("yyMMddHHmm")
logInfo ("Datum testen", "day0 ist {} und day1 ist {} ", day_1,day_2)
var day0 = new DateTime(localLastMeasurement_00.state.toString).toString("yyMMdd")
var day1 = new DateTime(localLastMeasurement_00.state.toString).plusDays(1).toString("yyMMdd")
var day2 = new DateTime(localLastMeasurement_00.state.toString).plusDays(2).toString("yyMMdd")
logInfo ("Datum testen", "day0 ist {} day1 ist {} day2 ist {} day3 ist {} day4 ist {} day5 ist {}", day0, day1, day2)
val day_act = new DateTime(now.toLocalDateTime.toString).toString("yyMMddHHmm")
logInfo ("Datum testen", "aktuell now1 ist {} ", day_act)
val morning_start = now.withTimeAtStartOfDay.plusDays(1).minusHours(18)
logInfo ("Datum testen", "morningstart ist {} ", morning_start)
val morning_start1 = now.withTimeAtStartOfDay.plusDays(0).minusHours(0)
logInfo ("Datum testen", "morningstart1 ist {} ", morning_start1)
val morning_start2 = new DateTime(now.withTimeAtStartOfDay.plusDays(1).plusHours(7))
logInfo ("Datum testen", "morningstart2 ist {} ", morning_start2)
val morning_start3 = new DateTime(now.withTimeAtStartOfDay).toString("HHmm")
logInfo ("Datum testen", "morningstart3 ist {} ", morning_start3)
var Number morning_start4 = new DateTime(now.withTimeAtStartOfDay).toString("HHmm")
logInfo ("Datum testen", "morningstart4 ist {} ", morning_start4)
var Number morning_start5 = new DateTime(now.withTimeAtStartOfDay.plusHours(7)).toString("HHmm")
logInfo("Datum testen", "morningstart5 ist {} ", morning_start5)
var morning_start6 = now().toString("HHmm")
logInfo("Datum testen", "morningstart6 ist {} ", morning_start6)
var morning_start7 = (now.withTimeAtStartOfDay.plusHours(7)).getHourOfDay
logInfo("Datum testen", "morningstart7 ist {} ", morning_start7)
var morning_start8 = now.withTimeAtStartOfDay.getHourOfDay
logInfo("Datum testen", "morningstart8 ist {} ", morning_start8)
val morning_now = now.toLocalDateTime
logInfo ("Datum testen", "morningnow ist {} ", morning_now)
val day_now = now.toLocalDateTime.toString("yyMMddHHmm")
logInfo ("Datum testen", "aktuell start ist {} ", day_now)
val day_test = new DateTime(now).toString("yyMMddHHmm")
logInfo ("Datum testen", "aktuell test ist {} ", day_test)
val day_test1 = new DateTime(now)
logInfo ("Datum testen", "aktuell test1 ist {} ", day_test1)
val day_test_now = now
logInfo ("Datum testen", "aktuell test_now ist {} ", day_test_now)
if ((now.withTimeAtStartOfDay.plusHours(22)).toString("HHmm") <= now().toString("HHmm") && (now.withTimeAtStartOfDay.plusHours(23)).toString("HHmm") >= now().toString("HHmm")) {
logInfo("Datum testen","Na geht doch")
}
if (now.withTimeAtStartOfDay.plusHours(22).getHourOfDay >= 22 && now.withTimeAtStartOfDay.plusHours(23).getHourOfDay <= 23) {
logInfo("Datum testen","Na geht doch oder auch nicht")
}
var Number min = 13
var Number max = 15
if (now.withTimeAtStartOfDay.plusHours(min).getHourOfDay >= min && now.withTimeAtStartOfDay.plusHours(max).getHourOfDay <= max) {
logInfo("Datum testen","und es geht doch: " + now().getHourOfDay )
}
if (now.withTimeAtStartOfDay.plusHours(min).getHourOfDay <= now().getHourOfDay && now.withTimeAtStartOfDay.plusHours(max).getHourOfDay > now.getHourOfDay()) {
logInfo("Datum testen","wie wär's damit")
}
if(now.isBefore((Sunset_Time_Test.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)) { // https://community.openhab.org/t/solved-datetimetype-is-deprecated/37296/31
logInfo("Datum testen", "Line 70 - now {} is before {} ", now, Sunset_Time_Test.state as DateTimeType)
return;
}
end