summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conversion/kabcconversion.cpp6
-rw-r--r--tests/kcalconversiontest.cpp32
2 files changed, 35 insertions, 3 deletions
diff --git a/conversion/kabcconversion.cpp b/conversion/kabcconversion.cpp
index 76d9597..0280213 100644
--- a/conversion/kabcconversion.cpp
+++ b/conversion/kabcconversion.cpp
@@ -703,7 +703,11 @@ Kolab::Contact fromKABC(const KABC::Addressee &addressee)
if (!spouse.isEmpty()) {
c.setRelateds(std::vector<Kolab::Related>() << Kolab::Related(Kolab::Related::Text, toStdString(spouse), Kolab::Related::Spouse));
}
- c.setBDay(fromDate(KDateTime(addressee.birthday(), KDateTime::ClockTime)));
+ QDateTime bDay = addressee.birthday();
+ if (!bDay.time().isValid()) {
+ bDay.setTime(QTime(0,0,0));
+ }
+ c.setBDay(fromDate(KDateTime(bDay, KDateTime::ClockTime)));
c.setAnniversary(fromDate(KDateTime(QDate::fromString( addressee.custom(QLatin1String("KADDRESSBOOK"), QLatin1String("X-Anniversary")), Qt::ISODate ), KDateTime::ClockTime)));
if (!addressee.photo().isEmpty()) {
std::string mimetype;
diff --git a/tests/kcalconversiontest.cpp b/tests/kcalconversiontest.cpp
index c62a8e0..9933683 100644
--- a/tests/kcalconversiontest.cpp
+++ b/tests/kcalconversiontest.cpp
@@ -530,6 +530,28 @@ void KCalConversionTest::testContactConversion_data()
QTest::newRow("bday") << kcal << kolab;
}
{
+ //QDateTime with invalid QTime
+ // QTime() -> isNull=true, isValid=false
+ // and also QDateTime isValid=false
+ //this kind of QDateTime is used to "reflect", that the vCard has a date-only value
+
+ KABC::Addressee kcal;
+ kcal.setUid("uid");
+ kcal.setFormattedName("name");
+ QDateTime dt(QDate(2012,2,2));
+ dt.setTime(QTime());
+ QCOMPARE(dt.isValid(), false);
+ kcal.setBirthday(dt);
+
+ //Because QDateTime doesn't know date-only values we always end up with a date-time
+ Kolab::Contact kolab;
+ kolab.setUid("uid");
+ kolab.setName("name");
+ kolab.setBDay(Kolab::cDateTime(2012,2,2,0,0,0));
+
+ QTest::newRow("invalid_qdatetime") << kcal << kolab;
+ }
+ {
KABC::Addressee kcal;
kcal.setUid("uid");
//The first address is always the preferred
@@ -566,8 +588,14 @@ void KCalConversionTest::testContactConversion()
foreach (const QString &mail, e.emails()) {
QCOMPARE(e.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail)), kcal.custom(QLatin1String("KOLAB"), QString::fromLatin1("EmailTypes%1").arg(mail)));
}
- QCOMPARE(e.birthday(), kcal.birthday());
-
+
+ if (!kcal.birthday().isValid()) {
+ QCOMPARE(e.birthday().date(), kcal.birthday().date());
+ QCOMPARE(e.birthday().time(), QTime(0,0,0));
+ } else {
+ QCOMPARE(e.birthday(), kcal.birthday());
+ }
+
const Kolab::Contact &b = fromKABC(kcal);
QCOMPARE(b.uid(), kolab.uid());
QCOMPARE(b.name(), kolab.name());