kcms/dateandtime: Calculate timeDiff before doing blocking things

It can take an arbitrary amount of time until the user answers authorizes
the change, during that time in the real world keeps running, the set time
by the user doesn't change once set. Calculate the diffrence in time beforehand
to keep it as close as possible to what the user wanted.
This commit is contained in:
David Redondo 2026-09-30 16:15:02 +02:00
parent 10b3bda631
commit e4805a6d4a

View file

@ -41,6 +41,8 @@ KclockModule::KclockModule(QObject *parent, const KPluginMetaData &metaData)
bool KclockModule::timedatedSave()
{
const qint64 timeDiff = dtime->userTime().toMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch();
OrgFreedesktopTimedate1Interface timedateIface(QStringLiteral("org.freedesktop.timedate1"),
QStringLiteral("/org/freedesktop/timedate1"),
QDBusConnection::systemBus());
@ -59,9 +61,7 @@ bool KclockModule::timedatedSave()
qWarning() << "Failed to enable NTP" << reply.error().name() << reply.error().message();
return false;
}
if (!dtime->ntpEnabled()) {
qint64 timeDiff = dtime->userTime().toMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch();
//*1000 for milliseconds -> microseconds
auto reply = timedateIface.SetTime(timeDiff * 1000, true, true);
reply.waitForFinished();