Hi all,
I want to call a function every two hours between 8 am and midnight, but it is not working as expected.
I initialize the timers like this:
timer_table = {}
for h = 7,23,2 do
local timestring = h..":55","1d"
print(timestring)
local timer = hs.timer.doAt(timestring,amazon_salesrank, true)
table.insert(timer_table, timer)
end
The hammer spoon console shows these lines:
2018-01-17 11:52:55: 7:55
2018-01-17 11:52:55: 9:55
2018-01-17 11:52:55: 11:55
2018-01-17 11:52:55: 13:55
2018-01-17 11:52:55: 15:55
2018-01-17 11:52:55: 17:55
2018-01-17 11:52:55: 19:55
2018-01-17 11:52:55: 21:55
2018-01-17 11:52:55: 23:55
After each first call of such a repeating timer function, the timer is no longer running:
function check_timers()
for ix,timer in ipairs(timer_table) do
if timer:running() then
print( ("timer %d: next trigger in %.1f hours"):format(ix, timer:nextTrigger()/3600) )
else
print("timer is not running")
-- timer:start()
end
end
end
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "t", check_timers)
The console shows:
2018-01-17 12:00:03: timer 1: next trigger in 19.9 hours
2018-01-17 12:00:03: timer 2: next trigger in 21.9 hours
2018-01-17 12:00:03: timer is not running
2018-01-17 12:00:03: timer 4: next trigger in 1.9 hours
2018-01-17 12:00:03: timer 5: next trigger in 3.9 hours
2018-01-17 12:00:03: timer 6: next trigger in 5.9 hours
2018-01-17 12:00:03: timer 7: next trigger in 7.9 hours
2018-01-17 12:00:03: timer 8: next trigger in 9.9 hours
2018-01-17 12:00:03: timer 9: next trigger in 11.9 hours
Am I using the doAt-function wrong or is there a bug?
Regards
Alfred