I’m trying to do something really simple but am having some issues. Maybe I’m going about this the wrong way, not sure.
In my smart app, my app is storing when it last performed various actions. I then want to show that date/time on the settings page. Here is the basic function that is designed to take the timestamp and convert it into a printable date:
def showLastDate(Long timestamp) {
log.debug “Date: ‘${timestamp}’”
def lastDate = new Date(timestamp).format(“yyyy-MM-dd HH:mm”)
return lastDate
}
This function is then used in my preferences section:
preferences {
section(“Last Alert: ${showLastDate(atomicState.lastActionTimeStamp)}”)
}
With this I always get a compile error java.lang.IllegalArgumentException on the “def lastDate” line. That seemed odd so I verified that the timestamp (i.e. 1521573853473) is pulled from the state value and passed into showLastDate() and is logged as expected.
If I put a static numeric value in the code, it works. If I try to do a conversion on the passed value to a Long, it also gets the same error so it has to be related to what is being passed. I’m guessing there is some typecasting issue here but for the life of me I just don’t see it.