From 38d2b124d86bfc33df6baf368b2b65696f260b93 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 24 Jun 2012 11:25:06 +0200 Subject: [PATCH] Fix datetime serialization appending two 'Z' at the end with Qt >= 4.8. --- src/format/KeePass2XmlWriter.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/format/KeePass2XmlWriter.cpp b/src/format/KeePass2XmlWriter.cpp index 9a9b28d43..c64ba796a 100644 --- a/src/format/KeePass2XmlWriter.cpp +++ b/src/format/KeePass2XmlWriter.cpp @@ -440,8 +440,16 @@ void KeePass2XmlWriter::writeBool(const QString& qualifiedName, bool b) void KeePass2XmlWriter::writeDateTime(const QString& qualifiedName, const QDateTime& dateTime) { Q_ASSERT(dateTime.isValid()); + Q_ASSERT(dateTime.timeSpec() == Qt::UTC); - writeString(qualifiedName, dateTime.toUTC().toString(Qt::ISODate).append('Z')); + QString dateTimeStr = dateTime.toString(Qt::ISODate); + + // Qt < 4.8 doesn't append a 'Z' at the end + if (!dateTimeStr.isEmpty() && dateTimeStr[dateTimeStr.size() - 1] != 'Z') { + dateTimeStr.append('Z'); + } + + writeString(qualifiedName, dateTimeStr); } void KeePass2XmlWriter::writeUuid(const QString& qualifiedName, const Uuid& uuid)