mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-07-01 10:56:57 +03:00
NOISSUE eliminate timestamp strings
This commit is contained in:
parent
80b81c2c1e
commit
b54839b897
13 changed files with 97 additions and 81 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue