Time of day as relevance?

Is it possible to use clock time as relevance in a task or group?

I have a task that starts a service if it is stopped.
But I would like to only have the task be started at night and not at day time.

Yes we can. This took me bit of time to figure out, hope it’s helpful.

// Get the local computer's time_of_day
q: time of time (local time zone) of now
A: 10:33:09
T: 1.473 ms
I: singular time of day

// True only when the local time is before 6am or after 10pm
q: exists (time of time (local time zone) of now) whose (it < time_of_day "06:00:00" or it > time_of_day "22:00:00")
A: False
T: 0.993 ms
I: singular boolean

// True only when the local time is after 9am and before 5pm
q: exists (time of time (local time zone) of now) whose (it > time_of_day "09:00:00" and it < time_of_day "17:00:00")
A: True
T: 0.490 ms
3 Likes

Nice! Thank you :slight_smile:

There is an alternative to using relevance for a Task (not for a Group). When you take action, on the Execution tab you can choose Run Between and enter something like 6 p.m. to 6 a.m. This should restrict your service restart to after hours. We use this regularly to restrict actions to a service window.

See the Execution Tab documentation.

1 Like