summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-11-13 13:07:38 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-11-13 13:15:26 (GMT)
commit3f9174df3f7b1e3e75e213fa3a929ab1757e1c52 (patch)
treea1d296d840b6c90fa2aaf3f959095ca5ff75d123
parent493b409a21bcae1715a71b4408762b18c09f8ad5 (diff)
downloadlibkolab-3f9174df3f7b1e3e75e213fa3a929ab1757e1c52.tar.gz
Convert utc offset date times to utc.
-rw-r--r--conversion/commonconversion.cpp7
-rw-r--r--tests/timezonetest.cpp8
-rw-r--r--tests/timezonetest.h1
3 files changed, 16 insertions, 0 deletions
diff --git a/conversion/commonconversion.cpp b/conversion/commonconversion.cpp
index 3546395..7accd22 100644
--- a/conversion/commonconversion.cpp
+++ b/conversion/commonconversion.cpp
@@ -88,6 +88,13 @@ cDateTime fromDate(const KDateTime &dt)
date.setTime(t.hour(), t.minute(), t.second());
if (dt.timeType() == KDateTime::UTC) { //UTC
date.setUTC(true);
+ } else if (dt.timeType() == KDateTime::OffsetFromUTC) {
+ const KDateTime utcDate = dt.toUtc();
+ const QDate &d = utcDate.date();
+ date.setDate(d.year(), d.month(), d.day());
+ const QTime &t = utcDate.time();
+ date.setTime(t.hour(), t.minute(), t.second());
+ date.setUTC(true);
} else if (dt.timeType() == KDateTime::TimeZone) { //Timezone
//TODO handle local timezone?
//Convert non-olson timezones if necessary
diff --git a/tests/timezonetest.cpp b/tests/timezonetest.cpp
index 92f09ce..f2c1963 100644
--- a/tests/timezonetest.cpp
+++ b/tests/timezonetest.cpp
@@ -17,6 +17,7 @@
#include "timezonetest.h"
#include <conversion/timezoneconverter.h>
+#include <conversion/commonconversion.h>
#include <kolabformat/kolabobject.h>
#include <kolabformat/errorhandler.h>
#include "testutils.h"
@@ -165,6 +166,13 @@ void TimezoneTest::testTimezoneDaemonAvailable()
QVERIFY(KSystemTimeZones::isTimeZoneDaemonAvailable());
}
+void TimezoneTest::testUTCOffset()
+{
+ const Kolab::cDateTime expected(2013, 10, 23, 2, 0 ,0, true);
+ const KDateTime input(KDateTime::fromString("2013-10-23T04:00:00+02:00", KDateTime::RFC3339Date));
+ const Kolab::cDateTime result = Kolab::Conversion::fromDate(input);
+ QCOMPARE(result, expected);
+}
QTEST_MAIN( TimezoneTest )
diff --git a/tests/timezonetest.h b/tests/timezonetest.h
index ed2f33f..fa518a6 100644
--- a/tests/timezonetest.h
+++ b/tests/timezonetest.h
@@ -35,6 +35,7 @@ private slots:
void testKolabObjectReader();
void testFindLegacyTimezone();
void testTimezoneDaemonAvailable();
+ void testUTCOffset();
};
#endif // TIMEZONETEST_H