Compare LastUpdate to now

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…

Thanks in advance,

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))

thanks for your reply.
I tried it, but in this case the Designer says:

The method or field getZonedDateTime is undefined for the type DateTimeType.

I’m not sure whether this is actually an issue or just a mistake in the designer. But I think it’s actually an issue…


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.

No, this is a Designer problem, not a problem with the code.

I see, thanks!
I once tried the VS Editor but it didn’t any syntax-check at all. Maybe I need to take some time to get it working :slight_smile:

Again, thanks for your help!

It now supports full language syntax checking, though I don’t think it underlines errors inline. You have to look at the “Problems” tab at the bottom.

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?

You have to be running the latest 2.2 release and make sure you set the language server port property:

1 Like

Hi there,

OK now I got the VS Code working with the check of issues.

And the system still doesn’t want the code…

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…

I appreciate any hints.

Thanks and regards,

Ah, so the problem is now and what the method is expecting are different.

I think you can use:





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…

Hi did you ever work this out?

no, not yet. Still stuck at the same place…