Using a time input type, I'm trying to subtract now(), but I can't figure out how to do it. Is there a way to convert from a time input that is, for some odd reason, stored as a string?
groovy.lang.MissingMethodException: No signature of method: java.lang.Long.minus() is applicable for argument types: (java.lang.String) values: [2024-01-28T12:40:00.000-0500]
This is undoubtedly for compatibility with a certain other platform that did things that way. (Beyond the fact that I think it's serialized to/from JSON so it would need to use some format like this anyway but apparently just leaves out any magic.)
To get a real Date object you can manipulate however you want, use the timeToday() method.
(Other tips: call getTime() on that Date object if you want it in epoch time like now(), or use new Date() to get now as a Date object.)
The end goal is to have an input datetime as epoch millis. It's so much easier to deal with a Long than String or Date type. Using parse, I got Unparseable date: "2024-01-28T01:00:00.000-0500 so I figured maybe it needed to be a Date, but... no. My thought was if I could get parse to work, I could compute epoch in millis, but that was just a means tot he end, aka rabbit hole (and not sure how with leap years/seconds).
log.debug dateValue = 2024-01-28T01:00:00.000-0500
log.debug timeToday(dateValue) = Sun Jan 28 01:00:00 EST 2024
log.debug dateToTime(dateValue) = Sun Jan 28 01:00:00 EST 2024 [does the same thing as timeToday?]
log.debug (dateValue - now()) = 2024-01-28T01:00:00.000-0500 [no error, but not useful]
log.debug (timeToday(dateValue) - now()) = No signature of method: java.util.Date.minus() is applicable for argument types: (java.lang.Long) values: [1706460053212]
What I want is to get +/- millis when subtracting from now(), subtract another datetime input string, etc.
Here's one example - While fixing something in Advanced Thermostat yesterday I was working in this area - Take Note of line 179, 196 and the math on 198