DateTime vs. DateTimeType (OpenHAB 3.x)

Upgrading from OH 2.x to 3x and have questions about DateTime vs. DateTimeType when/where to use each. In the URL below, it references both of them but doesn’t clearly tell you which to use when/where.

In my .items file, I have DateTime defined for items. Do I change these to DateTimeType ?

In my .rules file, I have variables defined as DateTime. Do I change these to DateTimeType ?

I have changed some of the variables over in my .rules file which resulted in the compiled errors going away.

var	DateTimeType	Cal_Date0				= zonedDateTime.now()
var	DateTimeType	Cal_Date1				= zonedDateTime.now().plusDays(1)
var	DateTimeType	Cal_Date2				= zonedDateTime.now().plusDays(2)
var	DateTimeType	Cal_Date3				= zonedDateTime.now().plusDays(3)
var	DateTimeType	Cal_Date4				= zonedDateTime.now().plusDays(4)

this works also

var 				Cal_Date0 = new DateTimeType().zonedDateTime.now().plusDays(0)
var 				Cal_Date1 = new DateTimeType().zonedDateTime.now().plusDays(1)
var 				Cal_Date2 = new DateTimeType().zonedDateTime.now().plusDays(2)
var 				Cal_Date3 = new DateTimeType().zonedDateTime.now().plusDays(3)
var 				Cal_Date4 = new DateTimeType().zonedDateTime.now().plusDays(4)

Best, Jay

It’s actually pretty easy. DateTime is an Item Type. You’d only ever use it in a .items file.

DateTime type is the type for the State carried by a DateTime Item.

In rules in OH 3, there is no longer such a thing as DateTime. That came from a library that has been deprecated for years and was finally removed in OH 3. Instead of org.joda.time.DateTime you will use java.time.ZonedDateTime.

The two work mostly the same but there are some differences covered in the lists of breaking changes. There are also several postings on the forum showing how to use ZonedDateTime.

2 Likes