Error: 'timeInMillis' is not a member of 'java.time.ZonedDateTime'

Hi all,

I insert “val joda …” from the documentation as line 160 in my code,

rule "joda_test"
when
		Time cron "0 */1 * ? * *" // Every minute. 

then
	logInfo("demo", "           <<< joda_test started. >>> v01")
	// Convert DateTimeType to Joda DateTime
	val joda_LastOpen= new DateTime((Door_LastOpen.state as DateTimeType).zonedDateTime.timeInMillis)

	if (now.minusMinutes(1).isAfter(joda_LastOpen)) {
			logInfo("demo", "           *** true ***")
		}
end

but this gives me an error in openhab.log:

2018-10-05 21:48:03.636 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'joda_test': 'timeInMillis' is not a member of 'java.time.ZonedDateTime'; line 160, column 26, length 97

Can’t find a mistake in my code. Can someone help?

Not sure of the mistake but it is simpler to use:

val joda_LastOpen= new DateTime(Door_LastOpen.state.toString)
1 Like

Thank you very much! That works.

Should we add this to the documentation?
I don’t know if the error I got is my fault. If not, should the example in the documentation be replaced by your suggestion?

I would try to do that, if necessary.

The docs should be updated and I’m in favor of the approach I showed.

To correct your original error the proper way is

val joda_LastOpen= new DateTime((Door_LastOpen.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli

The docs should be updated to show both really.

1 Like

Hi Rich,

I have updated the docs and it is not online yet.
This is my pull request.

I did it, as described on the github help page, but at

Step 5. Merge your Pull Request

of this help page I don’t see a Merge pull request button and I don’t know how to go on from this point.
I think I need a little help with github because it’s the first time I’ve used it.

Could you please have a look?

A maintainer needs to review your PR and they are the only ones with the power to merge your changes.

If you haven’t yet, create a new Issue describing what needs to change. Then add a comment to your PR saying that it “Solves #XXX” which will link the PR to the Issue. That will probably draw the attention of the maintainers better than a “naked” PR.

I was simply a bit busy and currently i am nearly alone maintaining the docs repo.
I think all of us are happy to get new contributors to the docs (or any other openhab repo). :slight_smile:
So i have no problem with “naked” PRs. We can take care of missing stuff or improvements within the PR comments.

I have commented the pr and we will have the improvements in a short amount of time. :slight_smile:

1 Like