From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Howard Newsgroups: gmane.emacs.devel Subject: Re: Timers for weekly events Date: Wed, 24 Jul 2024 09:35:22 -0800 Message-ID: <87msm6r8v9.fsf@librehacker.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5260"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 24 19:36:49 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sWfuz-0001ED-3M for ged-emacs-devel@m.gmane-mx.org; Wed, 24 Jul 2024 19:36:49 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWftu-00036Y-Gj; Wed, 24 Jul 2024 13:35:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWftr-00033t-FK for emacs-devel@gnu.org; Wed, 24 Jul 2024 13:35:40 -0400 Original-Received: from mx.kolabnow.com ([212.103.80.155]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWftl-0007R0-GD; Wed, 24 Jul 2024 13:35:36 -0400 Original-Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id B24023430E15; Wed, 24 Jul 2024 19:35:29 +0200 (CEST) Authentication-Results: ext-mx-out013.mykolab.com (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-type:content-type:mime-version:message-id:date:date :in-reply-to:subject:subject:from:from:received:received :received; s=dkim20240523; t=1721842526; x=1723656927; bh=RikgKT Nz3R4mY0W5gVucmc9gEykON9OLsEZTvg5b3GQ=; b=cBDMdx/Pp3GU1Qnt1sO5aa FmO2Aom4CGMv/8uLXDfZuVQ2MaoNSJ36oxBPMOFnJLPUzvghCL2DrU/kb99WCpvb Y24p50NeQzHgFMbDM3xY14JJHVz6nYBBwcZSmW7nLP6KVgGrS7uZfaGw8mGGObe+ XpE/ZhghUgBmpvP7hGzhf3WMq05JpLQpZ4rhg7LGenztybAw6gjhG4BLX8BdWb/O xGOPRXS1SsZkEC//1F2xRMvUft7eXk/H1sZrnUpPuWpFWOqbQfUWPUocNMJ/3aj1 JbE5TTdLsKj96AtaC9aNXJllXW9JbsVf4A/JhsUJBh7Y4GQoLM3dgk1PxIJp9KRQ == X-Virus-Scanned: amavis at mykolab.com Original-Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out013.mykolab.com [127.0.0.1]) (amavis, port 10024) with ESMTP id 2RgIB_1MfUSm; Wed, 24 Jul 2024 19:35:26 +0200 (CEST) Original-Received: from int-mx009.mykolab.com (unknown [10.9.13.9]) by mx.kolabnow.com (Postfix) with ESMTPS id 7BC763430E13; Wed, 24 Jul 2024 19:35:25 +0200 (CEST) Original-Received: from ext-subm010.mykolab.com (unknown [10.9.6.10]) by int-mx009.mykolab.com (Postfix) with ESMTPS id 684AB20947DA; Wed, 24 Jul 2024 19:35:25 +0200 (CEST) In-Reply-To: Eli Zaretskii's message of "Wed, 24 Jul 2024 19:45:23 +0300 (33 minutes, 29 seconds ago)" Received-SPF: none client-ip=212.103.80.155; envelope-from=christopher@librehacker.com; helo=mx.kolabnow.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:322055 Archived-At: 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 . But it seems like this, or some other simple solution, should be readily available to all users of the timer library. -- Christopher Howard