summaryrefslogtreecommitdiff
path: root/xmlrpcpendingcall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xmlrpcpendingcall.cpp')
-rw-r--r--xmlrpcpendingcall.cpp42
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);