Subject: Re: bug#39099: 26.3; display-time delay after PC sleep

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 30 Aug 2021 03:40:32 +0200

[email-masked] writes:

> Explicitly calling display-time restarts display-time-timer.
> Following lines are the contents of "display time log" buffer.
>
> Thu Jan 23 16:01:03 2020
> Thu Jan 23 16:02:00 2020
> Thu Jan 23 16:03:00 2020
> Thu Jan 23 16:04:00 2020

Right, because it's doing

(run-at-time t 60 ...)

which means that we should only run at each integral multiple of 60.

> Thu Jan 23 16:29:43 2020
> Thu Jan 23 16:29:43 2020
> Thu Jan 23 16:30:43 2020
> Thu Jan 23 16:31:43 2020

But then after sleeping, we're still running every 60 seconds -- but
it's not running on integral multiples?

Eli Zaretskii <[email-masked]> writes:

> I don't think this is specific to Windows.  The underlying problem
> here is that our timers are interval timers: the next time a timer
> fires is set by adding the interval to the time it fires now.  So if
> Emacs doesn't get CPU for a long time, it will start counting time
> from the first moment it gets CPU again.

It sounds like something else is going on here.  It's adding 60 seconds
correctly -- but not computing the integral multiples correctly...  So
it sounds like somehow `timer-next-integral-multiple-of-time' is
computing things incorrectly after sleeping?

I had a look at the function, and I couldn't see anything obviously
wrong with it.

Here's a test case:

(format-time-string "%H:%M:%S"
  (timer-next-integral-multiple-of-time (current-time) 60))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no