NOISSUE eliminate timestamp strings

This commit is contained in:
Petr Mrázek
2016-03-02 03:03:44 +01:00
parent 80b81c2c1e
commit b54839b897
13 changed files with 97 additions and 81 deletions

View File

@@ -1,23 +1,33 @@
#include <QDateTime>
#include <QString>
#include "ParseUtils.h"
#include <QDebug>
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;
}