I’ve got one item with a DateTime and another item that contains seconds. I’d like to fill a third item with the value that results from the addition of the seconds to the DateTime. I know I need a rule, but that’s about as far as I’ve gotten.
Can anyone point me to the right direction, thank you.
Getting a bit further, but still not even close. In order to use plusSeconds i apparently need to cast my Item of type DateTimeItem to a DateTime, but how is that done? I can’t find any viable examples with Google… Anybody able to help?
Edit: Apparently the way to get DateTime from a DateTimeItem is: var DateTime StartTime = new DateTime((RecordingStart1.state as DateTimeType).calendar.timeInMillis)
Which seems overly complicated IMHO, but that works. but now, how do you cast/convert a DateTime to a DateTimeItem?
Finally figured it out, I don’t know if it’s be best solution, but it works. I’d be really happy if someone could confirm or give the proper way, but this is whatI ended up using:
import org.joda.time.DateTime rule "RecordingEnd1" when Item RecordingStart1 received update then val duration = (RecordingDuration1.state as DecimalType).intValue val DateTime StartTime = new DateTime((RecordingStart1.state as DateTimeType).calendar.timeInMillis) var DateTime EndTime = StartTime.plusSeconds(duration) postUpdate(RecordingEnd1, new DateTimeType(EndTime.toCalendar(null))) end