quickshell icon indicating copy to clipboard operation
quickshell copied to clipboard

SystemClock breaks across Daylight Saving Time transitions

Open just-some-entity opened this issue 1 year ago • 3 comments

When the Daylight Saving Time transitioned today, the scheduling of the SystemClock breaks and the interval computed in SystemClock::schedule (this->timer.start(static_cast(delay)) to be precise) becomes a negative number, printing the warning "WARN: QTimer::start: negative intervals aren't allowed; the interval will be set to 1ms." every time the timer is started, flooding the console output.

just-some-entity avatar Oct 26 '25 01:10 just-some-entity

Hit this again at this year's fall-back (2026-10-25, Europe/Berlin, 03:00 CEST -> 02:00 CET) on quickshell 0.3.1 with Qt 6.11.2. src/core/clock.cpp is identical in v0.3.1, v0.3.2 and current master (9b0f339), so it still applies. Here is what happens and a reproducer.

The moment the clock went back, the shell started logging

WARN: QTimer::start: negative intervals aren't allowed; the interval will be set to 1ms.

at roughly 1000 to 1500 lines per second (366k journal lines in about four minutes) and dateChanged fired at the same rate. It survives shell restarts and only stops at 03:00 CET, when the wall time is unambiguous again. Removing the one SystemClock { precision: SystemClock.Minutes } from the config stops it immediately.

During that hour the published date also carries the wrong offset. With the system at 02:24 CET the clock reports 02:24:00 CEST, one hour early in UTC terms.

Cause

SystemClock::schedule() (src/core/clock.cpp:61-88) does its arithmetic on a local-time QDateTime:

auto currentTime = QDateTime::currentDateTime();      // :66
...
nextTime.setTime(QTime(h, m, s));                     // :74-78  truncate to precision
nextTime = nextTime.addSecs(60);                      // :81
auto delay = currentTime.msecsTo(nextTime);           // :84
this->timer.start(static_cast<qint32>(delay));        // :86

QDateTime::setTime(QTime, TransitionResolution = LegacyBehavior) re-resolves the wall time, and LegacyBehavior is RelativeToBefore (Qt 6.7+). In the repeated hour the wall time is ambiguous and RelativeToBefore picks the offset from before the transition, so 02:24 CET (01:24Z) turns into 02:24 CEST (00:24Z). addSecs(60) gives 02:25 CEST, about 59 minutes in the past, and delay comes out around -3.5e6 ms. QTimer clamps that to 1 ms and fires, onTimeout() (:32-35) calls schedule() again with the same inputs, and it loops at about 1 kHz for the rest of the hour.

SystemClock::setTime() (:47-56) runs the same setTime(QTime(...)) on a local QDateTime, which is why date is in CEST during that hour.

Commit 1d2bf5d ("core/clock: fix behavior with odd time changes") removed the earlier if (delay < 0) guard, so nothing catches the negative delay now.

Reproduce

shell.qml:

import QtQuick
import Quickshell

ShellRoot {
  SystemClock {
    id: clock
    precision: SystemClock.Minutes
    onDateChanged: console.log("tick", Qt.formatDateTime(clock.date, "yyyy-MM-dd HH:mm:ss t"))
  }
}

Run it while the local wall time is inside a fall-back repeated hour, for example with the system clock at 2026-10-25 01:30:00 UTC (02:30 CET, second pass):

TZ=Europe/Berlin timeout 10 quickshell -p ./shell.qml 2>&1 | grep -c 'negative intervals'

Live run at 02:24 CET today: 9076 warnings and 9074 dateChanged ticks in 10 seconds, every tick reporting 02:24:00 CEST. Same command with TZ=UTC: 0 warnings. Any other repeated hour should behave the same (TZ=America/New_York at 2026-11-01 06:30Z, for instance). Precision Seconds and Hours go through the same path.

Possible fix

Work on epoch milliseconds plus the current UTC offset instead of re-resolving local wall time:

qint64 period = secondPrecision ? 1000 : minutePrecision ? 60000 : 3600000;
auto now = QDateTime::currentDateTime();
qint64 nowMs = now.toMSecsSinceEpoch();
qint64 offMs = qint64(now.offsetFromUtc()) * 1000;
qint64 nextMs = ((nowMs + offMs) / period + 1) * period - offMs;   // (0, period] ahead
this->timer.start(int(nextMs - nowMs));
this->targetTime = QDateTime::fromMSecsSinceEpoch(nextMs);

The existing <500 ms early-fire handling can stay by basing nowMs on targetTime.toMSecsSinceEpoch() in that case. setTime() should truncate the same way so date keeps the right offset. Only clamping delay to >= 1 would silence the warning but keep the 1 kHz loop.

AccursedGalaxy avatar Oct 25 '26 01:10 AccursedGalaxy

Independent confirmation from a different setup, with the practical impact measured — in case it helps prioritise.

Environment: Arch/Omarchy, Hyprland 0.56.2 (Lua config), quickshell 0.3.2.r7.g2b4501a, TZ=Europe/London.

Same bug, same window, same magnitude, from the GMT side of the transition (fallback is 02:00 BST → 01:00 GMT, so the repeated hour is 01:00–02:00 local). Reproduced by mirroring schedule() exactly in PyQt6 at 01:33:04 GMT:

now        : 2026-10-25 01:33:04.383 GMT
truncated  : 2026-10-25 01:33:00.000 BST   (resolved instant: 00:33 UTC)
target+60s : 2026-10-25 01:34:00.000 BST
delay ms   : -3544383                     -> QTimer::start(-3544383)
UTC-safe   : +55617 ms                    (boundary computed in UTC)

Practical impact, since this is more than log spam: at Minutes precision inside a visible surface, each of those ticks re-emits dateChanged, and a clock consumer re-lays-out its label per tick. On a 4-core Haswell with an omarchy.clock bar widget:

  • ~1,200 negative intervals warnings/s and the same rate of dateChanged
  • quickshell 47–53% CPU (main thread ~35%, render thread ~20%)
  • Hyprland 25–68% CPU compositing the resulting repaints, load average 2.7
  • RSS churn up to 1.2 GB, which settles flat within ~3 minutes of the hour ending (so it reads like a leak but isn't one)

It self-heals exactly at the end of the repeated hour — measured 47% → 0% and warnings → 0 at 02:00:45, with nothing touched.

Two things worth recording for anyone searching:

  1. This is not specific to a bar clock, and not specific to the DST date: any system clock step backwards into a repeated local time (NTP correction, manual change) will trigger the same loop.
  2. Agreed on the epoch-ms fix being the real one. Clamping delay to >= 1 (as the guard removed in 1d2bf5d did) silences the warning but leaves the 1 kHz loop — it trades log spam for a CPU fire, so please don't take that route.

Consumer-side workaround I applied locally, in case it's useful to reference: replaced SystemClock with a minute timer whose interval is 60000 - (Date.now() % 60000) + margin, clamped to >= 250 ms. Epoch milliseconds are never ambiguous, so a clock or zone step can only make it tick early, never spin.

4rarius avatar Oct 25 '26 11:10 4rarius

Same fall-back, TZ=Europe/Lisbon (01:59:59 WEST → 01:00 WET), Omarchy 4.0.6, quickshell 0.3.2.r7.g2b4501a, machine locked and idle, so nothing was there to notice the CPU.

One consequence worth adding: the warning goes to $XDG_RUNTIME_DIR/quickshell/by-id/<id>/log.log as well, and at ~1 kHz it reached 708 MB and filled a default 763 MB /run/user/<uid> tmpfs in about 50 minutes, before the repeated hour ended. That took out uwsm's app daemon (its flag file lives on the same tmpfs), so every launch keybinding failed with "App failure: Invalid arguments" until the log was truncated. Details in #1161.

otterbotter avatar Oct 25 '26 11:10 otterbotter