emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Timers for weekly events


From: Eli Zaretskii
Subject: Re: Timers for weekly events
Date: Wed, 24 Jul 2024 21:38:40 +0300

> X-Spam-Status: No, score=-0.999 tagged_above=-10 required=5
>  tests=[ALL_TRUSTED=-1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
> From: Christopher Howard <christopher@librehacker.com>
> Cc: emacs-devel@gnu.org
> Date: Wed, 24 Jul 2024 09:35:22 -0800
> 
> So, let's say you want to have a run-at-time call in your init.el, which 
> starts a timer that will execute once per week, say Tuesday at 4am. How 
> exactly do you go about this?
> 
> One option would be you could pass a time of day to run-at-time. However, 
> then the function you call needs to implement two things: (1) it needs to 
> first check if it is on the right day of the week; (2) due to the design of 
> run-at-time, it will need to check if the time is *actually* the correct time 
> of day, since when passing a time-of-day to run-at-time, run-at-time will go 
> ahead and call the function if the specified time of day has already occured 
> anytime in the past day. (I once mistakenly reported this as a bug.)
> 
> Alternatively, we can pass in a relative time (number of seconds) until the 
> next occurrence of Tuesday 4am. But how does the user calculate that value, 
> without having to supply his own additional function that somehow works out 
> the logic and math? So far as I know, there isn't any built in elisp function 
> that makes such a calculation simple for the user.
> 
> I chose the second approach, as it does not require the callback to have any 
> knowledge of times and dates and such. And then I wrote my own function, as 
> documented in my post 
> <http://gem.librehacker.com/gemlog/starlog/20240723-0.gmi>. But it seems like 
> this, or some other simple solution, should be readily available to all users 
> of the timer library.

I suggest to take a look at midnight.el, it solves a very similar
problem: how to run a function at midnight of every day (or at a
user-defined offset from midnight).  It sounds like you want to do
something very similar, except in your case the function should run
once every 7 days, not once per day.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]