From b04a2a981a91ed58e55a275402cb2f9f73bd85a2 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 6 Apr 2013 17:42:47 +0200 Subject: timezone issue was tapatalk plugin bug, so remove workaround --- xmlrpcpendingcall.cpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'xmlrpcpendingcall.cpp') diff --git a/xmlrpcpendingcall.cpp b/xmlrpcpendingcall.cpp index 8f318bd..f6e4e60 100644 --- a/xmlrpcpendingcall.cpp +++ b/xmlrpcpendingcall.cpp @@ -73,18 +73,7 @@ QVariant XmlRpcPendingCall::decodeValue(QXmlStreamReader *r) if (!ok) value.clear(); } else if (r->name() == "dateTime.iso8601") { QString text = r->readElementText(); - QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate); - if (!dateTime.isValid()) { - // Qt seems not be happy without dashes - text.insert(4, '-'); - text.insert(7, '-'); - dateTime = QDateTime::fromString(text, Qt::ISODate); - if (!dateTime.isValid()) { - qWarning() << "Invalid dateTime format" << text; - return QVariant(); - } - } - value = QVariant::fromValue(dateTime); + value = QVariant::fromValue(decodeISODate(text)); } else if (r->name() == "base64") { QByteArray data = r->readElementText().toAscii(); value = QVariant::fromValue(QByteArray::fromBase64(data)); @@ -150,6 +139,35 @@ QVariant XmlRpcPendingCall::decodeValue(QXmlStreamReader *r) } } +QDateTime XmlRpcPendingCall::decodeISODate(QString text) +{ + if (text.length() < 8) { + // Too short! + return QDateTime(); + } + if (text[4].isNumber() && text[7].isNumber()) { + // Qt seems not be happy without dashes (YYYYMMDD vs YYYY-MM-DD) + text.insert(4, '-'); + text.insert(7, '-'); + } + // Qt will consider UTC offset "+00:00" invalid, so we replace it by "Z". + if (text.endsWith("+00:00") || text.endsWith("-00:00")) { + const int len = 6; // "+00:00" + const int pos = text.length() - len; + text.replace(pos, len, "Z"); + } else if (text.endsWith("+0000") || text.endsWith("-0000")) { + const int len = 5; // "+0000" + const int pos = text.length() - len; + text.replace(pos, len, "Z"); + } else if (text.endsWith("+00") || text.endsWith("-00")) { + const int len = 3; // "+00" + const int pos = text.length() - len; + text.replace(pos, len, "Z"); + } + QDateTime dt = QDateTime::fromString(text, Qt::ISODate); + return dt; +} + void XmlRpcPendingCall::handleRequestFinished() { Q_ASSERT(_state == StateWaitingReply); -- cgit v1.2.3