summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2015-04-21 17:54:40 +0200
committerChristian Mollekopf <mollekopf@kolabsys.com>2015-04-28 16:15:00 +0200
commit8dfd9f10b467b492ec073ee3f16f6c007ff16f45 (patch)
treefefa0407002472276168971e3b328b2e479b4ff8
parentbcbe1b8a26ca9f9eb180f7c19d334c1aa0f7fd2e (diff)
downloadlibkolab-8dfd9f10b467b492ec073ee3f16f6c007ff16f45.tar.gz
Build tests and ported away from KSystemTimeZones.
Next I have to get rid of KTimeZone entirely.
-rw-r--r--calendaring/datetimeutils.cpp4
-rw-r--r--conversion/commonconversion.cpp12
-rw-r--r--conversion/timezoneconverter.cpp34
-rw-r--r--icalendar/imip.cpp8
-rw-r--r--kolabformatV2/kolabbase.cpp4
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/calendaringtest.cpp2
-rw-r--r--tests/formattest.cpp2
-rw-r--r--tests/kcalconversiontest.cpp7
-rw-r--r--tests/timezonetest.cpp35
-rw-r--r--tests/timezonetest.h1
11 files changed, 31 insertions, 81 deletions
diff --git a/calendaring/datetimeutils.cpp b/calendaring/datetimeutils.cpp
index d6ea077..dc24f6b 100644
--- a/calendaring/datetimeutils.cpp
+++ b/calendaring/datetimeutils.cpp
@@ -18,14 +18,14 @@
#include "datetimeutils.h"
#include <qdebug.h>
-#include <ksystemtimezone.h>
+#include <QTimeZone>
#include "conversion/commonconversion.h"
namespace Kolab {
namespace DateTimeUtils {
KOLAB_EXPORT std::string getLocalTimezone()
{
- const QString tz = KSystemTimeZones::local().name();
+ const QString tz = QTimeZone::systemTimeZoneId();
return tz.toStdString();
}
diff --git a/conversion/commonconversion.cpp b/conversion/commonconversion.cpp
index 54c8518..57faf1d 100644
--- a/conversion/commonconversion.cpp
+++ b/conversion/commonconversion.cpp
@@ -20,8 +20,9 @@
#include <kolabformat/errorhandler.h>
#include <iostream>
-#include <ksystemtimezone.h>
+#include <KTimeZone>
#include <QUrl>
+#include <QTimeZone>
namespace Kolab {
namespace Conversion {
@@ -34,19 +35,14 @@ KDateTime::Spec getTimeSpec(bool isUtc, const std::string& timezone)
if (timezone.empty()) { //Floating
return KDateTime::Spec(KDateTime::ClockTime);
}
- //Timezone
//Convert non-olson timezones if necessary
const QString normalizedTz = TimezoneConverter::normalizeTimezone(QString::fromStdString(timezone));
- KTimeZone tz = KSystemTimeZones::zone(normalizedTz); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html
- if (!tz.isValid()) {
+ if (!QTimeZone::isTimeZoneIdAvailable(normalizedTz.toLatin1())) {
Warning() << "invalid timezone: " << QString::fromStdString(timezone) << ", assuming floating time";
- if (!KSystemTimeZones::isTimeZoneDaemonAvailable()) {
- Error() << "ktimezoned is not available and required for timezone interpretation";
- }
return KDateTime::Spec(KDateTime::ClockTime);
}
- return KDateTime::Spec(tz);
+ return KDateTime::Spec(KTimeZone(normalizedTz));
}
KDateTime toDate(const Kolab::cDateTime &dt)
diff --git a/conversion/timezoneconverter.cpp b/conversion/timezoneconverter.cpp
index 9d97b2d..697580d 100644
--- a/conversion/timezoneconverter.cpp
+++ b/conversion/timezoneconverter.cpp
@@ -17,18 +17,19 @@
#include "timezoneconverter.h"
#include <ktimezone.h>
-#include <ksystemtimezone.h>
#include <QRegExp>
#include <QStringList>
#include "kolabformat/errorhandler.h"
+#include <QTimeZone>
QString TimezoneConverter::normalizeTimezone(const QString& tz)
{
- KTimeZone timezone = KSystemTimeZones::zone(tz); //Needs ktimezoned (timezone daemon running) http://api.kde.org/4.x-api/kdelibs-apidocs/kdecore/html/classKSystemTimeZones.html
- if (timezone.isValid()) {
+ if (QTimeZone::isTimeZoneIdAvailable(tz.toLatin1())) {
return tz;
- } else if (!KSystemTimeZones::isTimeZoneDaemonAvailable()) {
- Error() << "ktimezoned is not available and required for timezone interpretation";
+ }
+ auto normalizedId = QTimeZone::windowsIdToDefaultIanaId(tz.toLatin1());
+ if (!normalizedId.isEmpty()) {
+ return normalizedId;
}
//We're dealing with an invalid or unknown timezone, try to parse it
QString guessedTimezone = fromCityName(tz);
@@ -38,15 +39,6 @@ QString TimezoneConverter::normalizeTimezone(const QString& tz)
if (guessedTimezone.isEmpty()) {
guessedTimezone = fromGMTOffsetTimezone(tz);
}
-// if (guessedTimezone.isEmpty()) {
-// //slower but also finds outdated zones
-// timezone = KSystemTimeZones::readZone(tz);
-// if (timezone.isValid()) {
-// //This thinks all kinds of shit is valid, including /etc/localtime. Let's verify again.
-// qDebug() << "found " << tz;
-// return tz;
-// }
-// }
Debug() << "Guessed timezone and found: " << guessedTimezone;
return guessedTimezone;
}
@@ -59,14 +51,12 @@ QString TimezoneConverter::fromGMTOffsetTimezone(const QString& tz)
QString TimezoneConverter::fromCityName(const QString& tz)
{
- const KTimeZones::ZoneMap zones = KSystemTimeZones::zones();
- KTimeZones::ZoneMap::const_iterator it = zones.constBegin();
+ const auto zones = QTimeZone::availableTimeZoneIds();
QHash<QString, QString> countryMap;
- for(;it != zones.constEnd(); it++) {
- const QString cityName = it.key().split('/').last();
-// qDebug() << it.key() << it.value().name() << cityName;
+ for (auto zone : zones) {
+ const QString cityName = zone.split('/').last();
Q_ASSERT(!countryMap.contains(cityName));
- countryMap.insert(cityName, it.key());
+ countryMap.insert(cityName, zone);
}
QRegExp locationFinder("\\b([a-zA-Z])+\\b", Qt::CaseSensitive, QRegExp::RegExp2);
@@ -77,9 +67,9 @@ QString TimezoneConverter::fromCityName(const QString& tz)
++pos;
}
const QString location = locationFinder.capturedTexts().first();
-// qDebug() << "location " << location;
+ qDebug() << "location " << location;
if (countryMap.contains(location)) {
-// qDebug() << "found match " << countryMap.value(location);
+ qDebug() << "found match " << countryMap.value(location);
return countryMap.value(location);
}
}
diff --git a/icalendar/imip.cpp b/icalendar/imip.cpp
index 13e0702..f4dca36 100644
--- a/icalendar/imip.cpp
+++ b/icalendar/imip.cpp
@@ -24,9 +24,9 @@
#include <KEmailAddress>
#include <kmime/kmime_message.h>
#include <QDebug>
-// #include <klocalizedstring.h>
-#include <ksystemtimezone.h>
#include <QTime>
+#include <QTimeZone>
+#include <KTimeZone>
/*
* The code in here is copy paste work from kdepim/calendarsupport.
*
@@ -206,7 +206,7 @@ QByteArray mailAttendees( const KCalCore::IncidenceBase::Ptr &incidence,
}
const QString body =
- KCalUtils::IncidenceFormatter::mailBodyStr( incidence, KSystemTimeZones::local() );
+ KCalUtils::IncidenceFormatter::mailBodyStr( incidence, KTimeZone(QTimeZone::systemTimeZoneId()) );
return createMessage(/* identity, */from, to, cc, subject, body, false,
bccMe, attachment/*, mailTransport */)->encodedContent();
@@ -230,7 +230,7 @@ QByteArray mailOrganizer( const KCalCore::IncidenceBase::Ptr &incidence,
subject = QString( "Free Busy Message" );
}
- QString body = KCalUtils::IncidenceFormatter::mailBodyStr( incidence, KSystemTimeZones::local() );
+ QString body = KCalUtils::IncidenceFormatter::mailBodyStr( incidence, KTimeZone(QTimeZone::systemTimeZoneId()) );
return createMessage( /*identity, */from, to, QString(), subject, body, false,
bccMe, attachment/*, mailTransport */)->encodedContent();
diff --git a/kolabformatV2/kolabbase.cpp b/kolabformatV2/kolabbase.cpp
index 7cea3a2..d66f389 100644
--- a/kolabformatV2/kolabbase.cpp
+++ b/kolabformatV2/kolabbase.cpp
@@ -37,8 +37,8 @@
#include <kcontacts/contactgroup.h>
#include <kcalcore/incidence.h>
#include <kcalcore/journal.h>
-#include <ksystemtimezone.h>
#include <QDebug>
+#include <KTimeZone>
using namespace KolabV2;
@@ -46,7 +46,7 @@ KolabBase::KolabBase( const QString& tz )
: mCreationDate( QDateTime::currentDateTime() ),
mLastModified( KDateTime::currentUtcDateTime() ),
mSensitivity( Public ),
- mTimeZone( KSystemTimeZones::zone( tz ) ),
+ mTimeZone( KTimeZone( tz ) ),
mHasPilotSyncId( false ), mHasPilotSyncStatus( false )
{
}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7a54555..5f4fc65 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -2,6 +2,9 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DTEST_DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
macro(addTest TEST_NAME)
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
target_link_libraries(${TEST_NAME} Qt5::Test kolab_static)
diff --git a/tests/calendaringtest.cpp b/tests/calendaringtest.cpp
index 8938be5..9af2068 100644
--- a/tests/calendaringtest.cpp
+++ b/tests/calendaringtest.cpp
@@ -19,7 +19,6 @@
#include "calendaringtest.h"
#include <QTest>
-#include <ksystemtimezone.h>
#include <kolabevent.h>
#include <iostream>
#include <calendaring/calendaring.h>
@@ -44,7 +43,6 @@ void compareEvents(const std::vector<Kolab::Event> &list1, const std::vector<Kol
void CalendaringTest::initTestCase()
{
- QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available");
}
void CalendaringTest::testCalendaringEvent()
diff --git a/tests/formattest.cpp b/tests/formattest.cpp
index 3d80d08..02f8475 100644
--- a/tests/formattest.cpp
+++ b/tests/formattest.cpp
@@ -23,7 +23,6 @@
#include <qprocess.h>
#include <qtemporaryfile.h>
#include <QBuffer>
-#include <ksystemtimezone.h>
#include <kolabcontainers.h>
#include <kolabformat.h>
@@ -77,7 +76,6 @@ static bool compareMimeMessage( const KMime::Message::Ptr &msg, const KMime::Mes
void FormatTest::initTestCase()
{
- QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available");
}
void FormatTest::testIncidence_data()
diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index 2b3fa73..ad3111a 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -20,10 +20,10 @@
#include <QtCore/QObject>
#include <QtTest/QtTest>
-#include <ksystemtimezone.h>
#include <kolabcontact.h>
#include <kcalcore/recurrence.h>
#include <kcontacts/addressee.h>
+#include <KTimeZone>
#include "conversion/kcalconversion.h"
#include "conversion/kcalconversion.cpp"
@@ -55,7 +55,6 @@ void compareAttendeesVectors(const KCalCore::Attendee::List &list, const KCalCor
void KCalConversionTest::initTestCase()
{
- QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available");
}
void KCalConversionTest::testDate_data()
@@ -63,7 +62,7 @@ void KCalConversionTest::testDate_data()
QTest::addColumn<Kolab::cDateTime>( "input" );
QTest::addColumn<KDateTime>( "result" );
- QTest::newRow( "datetime with tz" ) << Kolab::cDateTime("Europe/Zurich",2006,1,8,12,0,0) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KSystemTimeZones::zone("Europe/Zurich"));
+ QTest::newRow( "datetime with tz" ) << Kolab::cDateTime("Europe/Zurich",2006,1,8,12,0,0) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KTimeZone("Europe/Zurich"));
QTest::newRow( "floating datetime" ) << Kolab::cDateTime(2006,1,8,12,0,0, false) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KDateTime::Spec(KDateTime::ClockTime));
QTest::newRow( "utc datetime" ) << Kolab::cDateTime(2006,1,8,12,0,0, true) << KDateTime(KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KDateTime::UTC));
QTest::newRow( "date only" ) << Kolab::cDateTime(2006,1,8) << KDateTime(QDate(2006, 1, 8));
@@ -116,7 +115,7 @@ void KCalConversionTest::testDateTZ_data()
QTest::addColumn<Kolab::cDateTime>( "input" );
QTest::addColumn<KDateTime>( "result" );
- QTest::newRow( "berlin" ) << Kolab::cDateTime("Europe/Berlin",2006,1,8,12,0,0) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KSystemTimeZones::zone("Europe/Berlin"));
+ QTest::newRow( "berlin" ) << Kolab::cDateTime("Europe/Berlin",2006,1,8,12,0,0) << KDateTime(QDate(2006, 1, 8), QTime(12, 0, 0), KTimeZone("Europe/Berlin"));
}
void KCalConversionTest::testDateTZ()
diff --git a/tests/timezonetest.cpp b/tests/timezonetest.cpp
index 3188f46..df9fc70 100644
--- a/tests/timezonetest.cpp
+++ b/tests/timezonetest.cpp
@@ -23,39 +23,12 @@
#include "testutils.h"
#include <QTest>
-// #include <unicode/uversion.h>
-// #include <unicode/timezone.h>
-// #include <iostream>
#include <kcalcore/event.h>
#include <kcalcore/icalformat.h>
-#include <ksystemtimezone.h>
-
-// void icuFoo()
-// {
-// icu::UnicodeString s;
-// UErrorCode error;
-// // icu::TimeZone::getCanonicalID("GMT+01.00) Sarajevo/Warsaw/Zagreb", s, error);
-// // icu::TimeZone::getCanonicalID(icu::UnicodeString::fromUTF8("Europe/Zurich"), s, error);
-// icu::TimeZone::getCanonicalID(icu::UnicodeString::fromUTF8("GMT+01.00"), s, error);
-// std::string cs;
-// s.toUTF8String(cs);
-// std::cout << "This is the new timezone: " << cs << std::endl << u_errorName(error) << std::endl;
-// //
-// //
-// // icu::TimeZone *tz = icu::TimeZone::createTimeZone("GMT-8:00");
-// // icu::UnicodeString result;
-// // tz->getDisplayName(result);
-// // std::string stringresult;
-// // result.toUTF8String(stringresult);
-// // std::cout << stringresult;
-//
-// // icu::TimeZone *tz = icu::TimeZone::getStaticClassID();
-//
-// }
+#include <KTimeZone>
void TimezoneTest::initTestCase()
{
- QVERIFY2(KSystemTimeZones::isTimeZoneDaemonAvailable(), "Timezone support is required for this test. Either use libcalendaring or make sure KTimeZoned is available");
}
void TimezoneTest::testFromName()
@@ -170,12 +143,6 @@ void TimezoneTest::testIgnoreInvalidTimezone()
QVERIFY(normalized.isEmpty());
}
-void TimezoneTest::testTimezoneDaemonAvailable()
-{
- //With KDE it should be available and with libcalendaring it should return true
- QVERIFY(KSystemTimeZones::isTimeZoneDaemonAvailable());
-}
-
void TimezoneTest::testUTCOffset()
{
const Kolab::cDateTime expected(2013, 10, 23, 2, 0 ,0, true);
diff --git a/tests/timezonetest.h b/tests/timezonetest.h
index 6bd0c97..4838cb0 100644
--- a/tests/timezonetest.h
+++ b/tests/timezonetest.h
@@ -35,7 +35,6 @@ private slots:
// void testKolabObjectReader();
void testFindLegacyTimezone();
void testIgnoreInvalidTimezone();
- void testTimezoneDaemonAvailable();
void testUTCOffset();
void localTimezone();
};