Commit 1d2ea779 authored by David Jarvie's avatar David Jarvie
Browse files

CLazy/CLang-tidy fixes

parent 8bee2152
Pipeline #44947 passed with stage
in 9 minutes and 58 seconds
......@@ -2,7 +2,7 @@
This file is part of kalarmcal library, which provides access to KAlarm
calendar data.
SPDX-FileCopyrightText: 2005-2019 David Jarvie <djarvie@kde.org>
SPDX-FileCopyrightText: 2005-2020 David Jarvie <djarvie@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -19,6 +19,8 @@ using KAlarmCal::KADateTime;
#include <QDBusConnection>
#include <QDBusConnectionInterface>
//clazy:excludeall=non-pod-global-static
//TODO: test new methods
QTEST_GUILESS_MAIN(KADateTimeTest)
......@@ -296,7 +298,6 @@ void KADateTimeTest::constructors()
QTime t(3, 45, 14);
QDateTime dtLocal(d, t, Qt::LocalTime);
QDateTime dtUTC(d, t, Qt::UTC);
QDateTime dtLocal2(QDate(2016,3,27), QTime(1,0,0)); //Europe/London daylight savings change time
QTimeZone london("Europe/London");
QByteArray originalZone = qgetenv("TZ"); // save the original local time zone
......@@ -3292,26 +3293,26 @@ void KADateTimeTest::strings_format()
KADateTime dt(QDate(1999, 2, 3), QTime(6, 5, 0), KADateTime::LocalZone);
QString s = dt.toString(all);
QCOMPARE(s, QStringLiteral("1999.99.02.2.%1.%2.03.3.%3.%4-06.6.06.6.05.00?000?am.AM.-08.-0800.PST.America/Los_Angeles.Wednesday.Wed.February.Feb/.-08:00.%.")
.arg(locale.monthName(2, QLocale::LongFormat))
.arg(locale.monthName(2, QLocale::ShortFormat))
.arg(locale.dayName(3, QLocale::LongFormat))
.arg(locale.dayName(3, QLocale::ShortFormat)));
.arg(locale.monthName(2, QLocale::LongFormat),
locale.monthName(2, QLocale::ShortFormat),
locale.dayName(3, QLocale::LongFormat),
locale.dayName(3, QLocale::ShortFormat)));
KADateTime dtzone(QDate(1970, 4, 30), QTime(12, 45, 16, 25), london);
s = dtzone.toString(all);
QCOMPARE(s, QStringLiteral("1970.70.04.4.%1.%2.30.30.%3.%4-12.12.12.12.45.16?025?pm.PM.+01.+0100.BST.Europe/London.Thursday.Thu.April.Apr/:16.+01:00.%.")
.arg(locale.monthName(4, QLocale::LongFormat))
.arg(locale.monthName(4, QLocale::ShortFormat))
.arg(locale.dayName(4, QLocale::LongFormat))
.arg(locale.dayName(4, QLocale::ShortFormat)));
.arg(locale.monthName(4, QLocale::LongFormat),
locale.monthName(4, QLocale::ShortFormat),
locale.dayName(4, QLocale::LongFormat),
locale.dayName(4, QLocale::ShortFormat)));
KADateTime dtutc(QDate(2000, 12, 31), QTime(13, 45, 16, 100), KADateTime::UTC);
s = dtutc.toString(all);
QCOMPARE(s, QStringLiteral("2000.00.12.12.%1.%2.31.31.%3.%4-13.13.01.1.45.16?100?pm.PM.+00.+0000.UTC.UTC.Sunday.Sun.December.Dec/:16.+00:00.%.")
.arg(locale.monthName(12, QLocale::LongFormat))
.arg(locale.monthName(12, QLocale::ShortFormat))
.arg(locale.dayName(7, QLocale::LongFormat))
.arg(locale.dayName(7, QLocale::ShortFormat)));
.arg(locale.monthName(12, QLocale::LongFormat),
locale.monthName(12, QLocale::ShortFormat),
locale.dayName(7, QLocale::LongFormat),
locale.dayName(7, QLocale::ShortFormat)));
// fromString() without QList<QTimeZone> parameter
dt = KADateTime::fromString(QStringLiteral("2005/9/05/20:2,03"), QStringLiteral("%Y/%:m/%d/%S:%k,%M"));
......@@ -3320,16 +3321,16 @@ void KADateTimeTest::strings_format()
QCOMPARE(dt.timeType(), KADateTime::LocalZone);
dt = KADateTime::fromString(QStringLiteral("%1pm05ab%2t/052/20:2,03+10")
.arg(locale.dayName(1, QLocale::LongFormat))
.arg(locale.monthName(9, QLocale::LongFormat)),
.arg(locale.dayName(1, QLocale::LongFormat),
locale.monthName(9, QLocale::LongFormat)),
QStringLiteral("%a%p%yab%Bt/%e2/%S:%l,%M %z"));
QCOMPARE(dt.date(), QDate(2005, 9, 5));
QCOMPARE(dt.time(), QTime(14, 3, 20));
QCOMPARE(dt.timeType(), KADateTime::OffsetFromUTC);
QCOMPARE(dt.utcOffset(), 10 * 3600);
dt = KADateTime::fromString(QStringLiteral("%1pm05ab%2t/052/20:2,03+10")
.arg(locale.dayName(1, QLocale::ShortFormat))
.arg(locale.monthName(9, QLocale::ShortFormat)),
.arg(locale.dayName(1, QLocale::ShortFormat),
locale.monthName(9, QLocale::ShortFormat)),
QStringLiteral("%a%p%yab%Bt/%d2/%s:%l,%:M %z"));
QCOMPARE(dt.date(), QDate(2005, 9, 5));
QCOMPARE(dt.time(), QTime(14, 3, 20));
......
......@@ -3,7 +3,7 @@
This file is part of kalarmcal library, which provides access to KAlarm
calendar data. Qt5 version of KDE 4 kdelibs/kdecore/date/kdatetime.cpp.
SPDX-FileCopyrightText: 2005-2019 David Jarvie <djarvie@kde.org>
SPDX-FileCopyrightText: 2005-2020 David Jarvie <djarvie@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -1753,35 +1753,36 @@ QString KADateTime::toString(TimeFormat format) const
QString seconds;
if (d->time().second())
seconds = QLatin1String(":") + numString(d->time().second(), 2);
result += QStringLiteral("%1 %2 ").arg(numString(d->date().day(), 2))
.arg(shortMonth(d->date().month()));
result += QStringLiteral("%1 %2 ").arg(numString(d->date().day(), 2),
shortMonth(d->date().month()));
int year = d->date().year();
if (year < 0) {
result += QLatin1Char('-');
year = -year;
}
result += QStringLiteral("%1 %2:%3%4 ").arg(numString(year, 4))
.arg(numString(d->time().hour(), 2))
.arg(numString(d->time().minute(), 2))
.arg(seconds);
result += QStringLiteral("%1 %2:%3%4 ").arg(numString(year, 4),
numString(d->time().hour(), 2),
numString(d->time().minute(), 2),
seconds);
break;
}
case RFC3339Date: {
result += QStringLiteral("%1-%2-%3T%4:%5:%6")
.arg(numString(d->date().year(), 4))
.arg(numString(d->date().month(), 2))
.arg(numString(d->date().day(), 2))
.arg(numString(d->time().hour(), 2))
.arg(numString(d->time().minute(), 2))
.arg(numString(d->time().second(), 2));
.arg(numString(d->date().year(), 4),
numString(d->date().month(), 2),
numString(d->date().day(), 2),
numString(d->time().hour(), 2),
numString(d->time().minute(), 2),
numString(d->time().second(), 2));
int msec = d->time().msec();
if (msec) {
int digits = 3;
if (!(msec % 10))
if (!(msec % 10)) {
msec /= 10, --digits;
if (!(msec % 10))
msec /= 10, --digits;
result += QStringLiteral(".%1").arg(numString(d->time().msec(), digits));
if (!(msec % 10))
msec /= 10, --digits;
}
result += QStringLiteral(".%1").arg(numString(msec, digits));
}
if (d->specType == UTC)
return result + QLatin1Char('Z');
......@@ -2142,8 +2143,8 @@ KADateTime KADateTime::fromString(const QString &string, TimeFormat format, bool
d = QDate(year, 1, 1).addDays(day - 1);
if (!d.isValid() || (d.year() != year))
break;
day = d.day();
month = d.month();
//day = d.day();
//month = d.month();
} else {
// A month and day are specified
month = parts[3].leftRef(2).toInt(&ok);
......
......@@ -2227,7 +2227,7 @@ bool KAEvent::reminderDeferral() const
*/
void KAEvent::defer(const DateTime &dt, bool reminder, bool adjustRecurrence)
{
return d->defer(dt, reminder, adjustRecurrence);
d->defer(dt, reminder, adjustRecurrence);
}
void KAEventPrivate::defer(const DateTime &dateTime, bool reminder, bool adjustRecurrence)
......@@ -4039,7 +4039,7 @@ void KAEventPrivate::readAlarms(const Event::Ptr &event, AlarmMap *alarmMap, boo
// Check if it's an audio event with no display alarm
bool audioOnly = false;
for (Alarm::Ptr alarm : alarms) {
for (const Alarm::Ptr &alarm : alarms) {
bool done = false;
switch (alarm->type()) {
case Alarm::Display:
......@@ -5263,7 +5263,7 @@ bool KAEvent::convertKCalEvents(const Calendar::Ptr &calendar, int calendarVersi
}
if (!cats.isEmpty()) {
for (Alarm::Ptr alarm : alarms) {
for (Alarm::Ptr alarm : alarms) { //clazy:exclude=range-loop Can't use reference because 'alarms' is const
if (alarm->type() == Alarm::Display)
alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FONT_COLOUR_PROPERTY,
QStringLiteral("%1;;").arg(cats.at(0)));
......@@ -5931,8 +5931,10 @@ EmailAddressList &EmailAddressList::operator=(const Person::List &addresses)
*/
EmailAddressList::operator QStringList() const
{
int cnt = count();
QStringList list;
for (int p = 0, end = count(); p < end; ++p) {
list.reserve(cnt);
for (int p = 0; p < cnt; ++p) {
list += address(p);
}
return list;
......@@ -5996,8 +5998,10 @@ QString EmailAddressList::address(int index) const
*/
QStringList EmailAddressList::pureAddresses() const
{
int cnt = count();
QStringList list;
for (int p = 0, end = count(); p < end; ++p) {
list.reserve(cnt);
for (int p = 0; p < cnt; ++p) {
list += at(p).email();
}
return list;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment