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,33 +84,37 @@ 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)) {
tzName = zoneName; if (zoneName.contains(tz, Qt::CaseInsensitive)) {
dt = zoneDateTime; tzName = zoneName;
} else { dt = zoneDateTime;
foreach (const QByteArray &abbrev, zone.abbreviations()) { } else {
if (QString(abbrev).contains(tz, Qt::CaseInsensitive)) { foreach (const QByteArray &abbrev, zone.abbreviations()) {
tzName = abbrev; if (QString(abbrev).contains(tz, Qt::CaseInsensitive)) {
dt = zoneDateTime; tzName = abbrev;
} dt = zoneDateTime;
} }
} }
} }
if (dt.isValid()) {
break;
}
} }
return dt; return dt;