What about providing a function to the pimatic core that allows to calculate the difference between two dates.
Thats quite easy. Just tested it:
when ... then set $duration = diffDate("2018-01-01", "2018-02-01", "days")
This also works
$last-change = "2018-02-15 17:53:40"
when every 60 minutes then set $duration = diffDate($last-change, date(), "days")
when trigger:$duration < 1 then ...
For a quick solution just add the function to the VariableManager in the variables.coffee located in pimatic\lib folder. For a permanent solution ask @mwittig to add this to the next pimatic release.
exec: (dateIn1, dateIn2, format) ->
date1 = Date.parse(dateIn1)
date2 = Date.parse(dateIn2)
diff = date1 - date2
diff = diff / 1000
diff = diff / 1000 / 60
diff = diff / 1000 / 60 / 60
diff = diff / 1000 / 60 / 60 / 24
Regarding the use of Math.round() or Math.ceil() there needs to be a further discussion. I would suggest to use ceil() for positive differences and round() for negative ones.
That means the difference in days will be at least 1 as long as it isn’t <=0.
Half a day after passing the scheduled date, the difference will be -1 days.
By using always the round() function, the difference will be 0, 12 hours before and after the configured “schedule”.