Run "something" at certain time -tile?

Ah, that’s right. I recall running into this in the past. If the rule runs later in the day where it’s potentially already tomorrow in UTC, you can’t parse just the time. One trick is to concatenate in the current date with your time string, so when you parse the time you can be sure it’s the current time today:

So back to our example, that might look like:

#// add the current date to our timestamp to ensure it is parsed as 'today'
today = formatDate(now(), "YYYY-MM-DD ")
fulltime = concat(today, $targetTime)

#// parse the fulltime including today's date concatenated in
ts = date(fulltime, "YYYY-MM-DD hh:mm A") 

#// if the time is BEFORE now, add a day to it since we probably want that time tomorrow
ts = (ts < now()) ? addDays(ts, 1) : ts

#// calculate how many seconds until our targetTime (it's in millis, so convert to seconds)
(ts - now()) / 1000

In case you’re curious about alternative approaches, here’s one:

Alternative approach

Set Date Parts to Today
You have to set the date, month, and year otherwise you could be on the edge of a month or year and tomorrow is actually the next month or year

ts = date($targetTime, "hh:mm A") 

#// set the date, month, and year to today's
ts = setDatePart(ts, 'date', getDatePart(now(), 'date'))
ts = setDatePart(ts, 'month', getDatePart(now(), 'month'))
ts = setDatePart(ts, 'year', getDatePart(now(), 'year'))
1 Like