I’ll have to go through all the cases in the OP. It’s on my list of todos. There shouldn’t be too many changes though. Most of the commonly used stuff is the same between the two.
Potentially nothing. There are a few little cases though where you might run into exceptions. I don’t have a list of all errors I would expect you’ll see at this time though.
None. Joda is totally gone and is completely replaced by native Java time classes. However, now is still there and has the plusSeconds et al functions so it should be mostly transparent for you.
plusMinutes should definitely work without change. I’m not 100% positive about withTimeAtStartOfDay. But
now.withHour(0).withMinute(0).withSecond(0)
should be the equivalent. Here is the full JavaDoc for the class.
Thanks Rich.
A silly(?) question: how can I use the future Java code in OH2 today rather than Joda ?
now.withHour(0).withMinute(0).withSecond(0)
on current OH 2 (but running Java 11) gives me
2020-10-26 17:54:31.530 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'sage für den Rest des Tages erwartete Strommenge voraus': 'withHour' is not a member of 'org.joda.time.DateTime'; line 309, column 9, length 15
You can already replace Joda-Time in your OH 2.5 rules today with java.time. That’s how I did it and have no issues with time when using the same rules in OH 3.
And mind we’re in rules DSL so I think I cannot do ZonedDateTime.now() that’s giving errors.
Need to use ZonedDateTime::now. Same likely for the MIDNIGHT literal but no matter what I try it doesn’t work.
I’m using a rule which i found in the forum with OH 2.5 an Java 11.
It includes the following line:
val long now_epoch = now.toInstant.toEpochMilli
But the lines throwes the following exception:
18:28:45.012 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Update Power traffic light': 'toEpochMilli' is not a member of 'org.joda.time.Instant'; line 339, column 24, length 26