From b54839b8976b5c1455c838828f2bc92cdeb178eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 2 Mar 2016 03:03:44 +0100 Subject: NOISSUE eliminate timestamp strings --- logic/minecraft/ParseUtils.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'logic/minecraft/ParseUtils.cpp') diff --git a/logic/minecraft/ParseUtils.cpp b/logic/minecraft/ParseUtils.cpp index 8fccf403..473ca1de 100644 --- a/logic/minecraft/ParseUtils.cpp +++ b/logic/minecraft/ParseUtils.cpp @@ -1,23 +1,33 @@ #include #include #include "ParseUtils.h" +#include QDateTime timeFromS3Time(QString str) { return QDateTime::fromString(str, Qt::ISODate); } -bool parse_timestamp (const QString & raw, QString & save_here, QDateTime & parse_here) +QString timeToS3Time(QDateTime time) { - save_here = raw; - if (save_here.isEmpty()) - { - return false; - } - parse_here = timeFromS3Time(save_here); - if (!parse_here.isValid()) - { - return false; - } - return true; + // this all because Qt can't format timestamps right. + int offsetRaw = time.offsetFromUtc(); + bool negative = offsetRaw < 0; + int offsetAbs = std::abs(offsetRaw); + + int offsetSeconds = offsetAbs % 60; + offsetAbs -= offsetSeconds; + + int offsetMinutes = offsetAbs % 3600; + offsetAbs -= offsetMinutes; + offsetMinutes /= 60; + + int offsetHours = offsetAbs / 3600; + + QString raw = time.toString("yyyy-MM-ddTHH:mm:ss"); + raw += (negative ? QChar('-') : QChar('+')); + raw += QString("%1").arg(offsetHours, 2, 10, QChar('0')); + raw += ":"; + raw += QString("%1").arg(offsetMinutes, 2, 10, QChar('0')); + return raw; } -- cgit v1.2.3