Hi,
in a rule I want to check weather an item of type DateTime was changed within the last hour.
So the if looks like this:
(VSiPhone6_LocationLastUpdate.state as DateTimeType).calendar.after(now.minusMinutes(60))
Which seems to work (Designer doesn’t say anything about an error. But in the log I get:
The method getCalendar() from the type DateTimeType is deprecated
What’s the best way to achive this? It looks to me like working with DateTimes is not that easy…
This is very true sadly. Most people greatly underestimate how complex it actually is to handle date times on computers.
This is a new thing in OH 2.2 release. It is just a warning, not an error. It will still work like this for some time. The warning is mainly to indicate that at some point, the method may go away at some point and is not really supported any longer. So it is a good idea to change it.
I believe you don’t need to get the calendar to call after or isAfter (I forget which call is supported if either). If not you can use:
(VSiPhone6_LocationLastUpdate.state as DateTimeType).getZonedDateTime.isAfter(now.minusMinutes(60))
Designer is end of life. It is already behind and only going to become more and more behind as the rest of OH advances.
Starting with OH 2.0 it already marked somethings wrong erroneously and the number of things Designer will erroneously mark as wrong is only growing. The new VSCode is now the officially recommended editor.
Thanks. I installed the OH extension and I do see different colors and so on. But the problems tab at the bottom is completely empty, even if I enter something stupid.
Do I need to enable or trigger a check?
And it actually doesn’t work, a similar error is in the log:
An error occurred during the script execution: Could not invoke method: java.time.chrono.ChronoZonedDateTime.isAfter(java.time.chrono.ChronoZonedDateTime) on instance: 2018-01-13T11:43:29+01:00
I tried a little bit with the code, but as I’m not a developer it’s simply trial and error…
with .toString it says:
Type mismatch: cannot convert from string to ChronoZonedDateTime
and with millis:
Type mismatch: cannot convert from long to ChronoZonedDateTime
I think we’re getting closer but can’t figure out the last bit…