kdeplasma-addons: datetime runner optimization

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-03 13:26:41 +03:00
parent 29c60110d3
commit 48ed9841fe

View file

@ -84,21 +84,23 @@ void DateTimeRunner::match(Plasma::RunnerContext &context)
QDateTime DateTimeRunner::datetime(const QString &tz, QString &tzName) QDateTime DateTimeRunner::datetime(const QString &tz, QString &tzName)
{ {
QDateTime dt; QDateTime dt;
const QDateTime cdt = QDateTime::currentDateTimeUtc();
if (tz.compare(QLatin1String("UTC"), Qt::CaseInsensitive) == 0) { if (tz.compare(QLatin1String("UTC"), Qt::CaseInsensitive) == 0) {
tzName = QLatin1String( "UTC" ); tzName = QLatin1String( "UTC" );
dt = KTimeZone::utc().toZoneTime(QDateTime::currentDateTimeUtc()); dt = cdt;
return dt; return dt;
} }
foreach (const KTimeZone &zone, KSystemTimeZones::zones()) { foreach (const KTimeZone &zone, KSystemTimeZones::zones()) {
const QString zoneName = zone.name(); const QString zoneName = zone.name();
const QDateTime zoneDateTime = zone.toZoneTime(QDateTime::currentDateTimeUtc()); const QDateTime zoneDateTime = zone.toZoneTime(cdt);
if (zoneName.compare(tz, Qt::CaseInsensitive) == 0) { if (zoneName.compare(tz, Qt::CaseInsensitive) == 0) {
tzName = zoneName; tzName = zoneName;
dt = zoneDateTime; dt = zoneDateTime;
break; break;
} else if (!dt.isValid()) { }
if (zoneName.contains(tz, Qt::CaseInsensitive)) { if (zoneName.contains(tz, Qt::CaseInsensitive)) {
tzName = zoneName; tzName = zoneName;
dt = zoneDateTime; dt = zoneDateTime;
@ -110,6 +112,8 @@ QDateTime DateTimeRunner::datetime(const QString &tz, QString &tzName)
} }
} }
} }
if (dt.isValid()) {
break;
} }
} }