diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2013-04-06 17:42:47 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2013-04-06 17:42:47 +0200 |
commit | b04a2a981a91ed58e55a275402cb2f9f73bd85a2 (patch) | |
tree | 1fc1690f78fb40de214bc95361dff5fcbe516d0c /xmlrpcpendingcall.cpp | |
parent | a4626f5306ed3c5e52c28bb49d61ec50c7c2f329 (diff) | |
download | tapasboard-b04a2a981a91ed58e55a275402cb2f9f73bd85a2.tar.gz tapasboard-b04a2a981a91ed58e55a275402cb2f9f73bd85a2.zip |
timezone issue was tapatalk plugin bug, so remove workaround
Diffstat (limited to 'xmlrpcpendingcall.cpp')
-rw-r--r-- | xmlrpcpendingcall.cpp | 42 |
1 files changed, 30 insertions, 12 deletions
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); |