Add ability to parse more of "innovative" datetime formats. close #4760
This commit is contained in:
parent
0f2d7b9879
commit
24b6fbf36c
|
@ -92,7 +92,7 @@ class PlayerInterface : public QObject {
|
||||||
virtual void Play() = 0;
|
virtual void Play() = 0;
|
||||||
virtual void ShowOSD() = 0;
|
virtual void ShowOSD() = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Playing();
|
void Playing();
|
||||||
void Paused();
|
void Paused();
|
||||||
void Stopped();
|
void Stopped();
|
||||||
|
|
|
@ -100,8 +100,7 @@ QString PrettyTime(int seconds) {
|
||||||
|
|
||||||
QString ret;
|
QString ret;
|
||||||
if (hours)
|
if (hours)
|
||||||
ret.sprintf("%d:%02d:%02d", hours, minutes,
|
ret.sprintf("%d:%02d:%02d", hours, minutes, seconds); // NOLINT(runtime/printf)
|
||||||
seconds); // NOLINT(runtime/printf)
|
|
||||||
else
|
else
|
||||||
ret.sprintf("%d:%02d", minutes, seconds); // NOLINT(runtime/printf)
|
ret.sprintf("%d:%02d", minutes, seconds); // NOLINT(runtime/printf)
|
||||||
|
|
||||||
|
@ -162,15 +161,11 @@ QString PrettySize(quint64 bytes) {
|
||||||
if (bytes <= 1000)
|
if (bytes <= 1000)
|
||||||
ret = QString::number(bytes) + " bytes";
|
ret = QString::number(bytes) + " bytes";
|
||||||
else if (bytes <= 1000 * 1000)
|
else if (bytes <= 1000 * 1000)
|
||||||
ret.sprintf("%.1f KB",
|
ret.sprintf("%.1f KB", static_cast<float>(bytes) / 1000); // NOLINT(runtime/printf)
|
||||||
static_cast<float>(bytes) / 1000); // NOLINT(runtime/printf)
|
|
||||||
else if (bytes <= 1000 * 1000 * 1000)
|
else if (bytes <= 1000 * 1000 * 1000)
|
||||||
ret.sprintf("%.1f MB", static_cast<float>(bytes) /
|
ret.sprintf("%.1f MB", static_cast<float>(bytes) / (1000 * 1000)); // NOLINT(runtime/printf)
|
||||||
(1000 * 1000)); // NOLINT(runtime/printf)
|
|
||||||
else
|
else
|
||||||
ret.sprintf("%.1f GB",
|
ret.sprintf("%.1f GB", static_cast<float>(bytes) / (1000 * 1000 * 1000)); // NOLINT(runtime/printf)
|
||||||
static_cast<float>(bytes) /
|
|
||||||
(1000 * 1000 * 1000)); // NOLINT(runtime/printf)
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -564,24 +559,19 @@ bool ParseUntilElement(QXmlStreamReader* reader, const QString& name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime ParseRFC822DateTime(const QString& text) {
|
QDateTime ParseRFC822DateTime(const QString& text) {
|
||||||
// This sucks but we need it because some podcasts don't quite follow the
|
QRegExp regexp("(\\d{1,2}) (\\w{3,12}) (\\d+) (\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
||||||
// spec properly - they might have 1-digit hour numbers for example.
|
if (regexp.indexIn(text) == -1) {
|
||||||
QDateTime ret;
|
return QDateTime();
|
||||||
QRegExp re(
|
|
||||||
"([a-zA-Z]{3}),? (\\d{1,2}) ([a-zA-Z]{3}) (\\d{4}) "
|
|
||||||
"(\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
|
||||||
if (re.indexIn(text) != -1) {
|
|
||||||
ret = QDateTime(
|
|
||||||
QDate::fromString(QString("%1 %2 %3 %4")
|
|
||||||
.arg(re.cap(1), re.cap(3), re.cap(2), re.cap(4)),
|
|
||||||
Qt::TextDate),
|
|
||||||
QTime(re.cap(5).toInt(), re.cap(6).toInt(), re.cap(7).toInt()));
|
|
||||||
}
|
}
|
||||||
if (ret.isValid()) return ret;
|
|
||||||
// Because http://feeds.feedburner.com/reasonabledoubts/Msxh?format=xml
|
enum class MatchNames {
|
||||||
QRegExp re2(
|
DAYS = 1,
|
||||||
"(\\d{1,2}) ([a-zA-Z]{3}) (\\d{4}) "
|
MONTHS,
|
||||||
"(\\d{1,2}):(\\d{1,2}):(\\d{1,2})");
|
YEARS,
|
||||||
|
HOURS,
|
||||||
|
MINUTES,
|
||||||
|
SECONDS
|
||||||
|
};
|
||||||
|
|
||||||
QMap<QString, int> monthmap;
|
QMap<QString, int> monthmap;
|
||||||
monthmap["Jan"] = 1;
|
monthmap["Jan"] = 1;
|
||||||
|
@ -596,13 +586,28 @@ QDateTime ParseRFC822DateTime(const QString& text) {
|
||||||
monthmap["Oct"] = 10;
|
monthmap["Oct"] = 10;
|
||||||
monthmap["Nov"] = 11;
|
monthmap["Nov"] = 11;
|
||||||
monthmap["Dec"] = 12;
|
monthmap["Dec"] = 12;
|
||||||
|
monthmap["January"] = 1;
|
||||||
|
monthmap["February"] = 2;
|
||||||
|
monthmap["March"] = 3;
|
||||||
|
monthmap["April"] = 4;
|
||||||
|
monthmap["May"] = 5;
|
||||||
|
monthmap["June"] = 6;
|
||||||
|
monthmap["July"] = 7;
|
||||||
|
monthmap["August"] = 8;
|
||||||
|
monthmap["September"] = 9;
|
||||||
|
monthmap["October"] = 10;
|
||||||
|
monthmap["November"] = 11;
|
||||||
|
monthmap["December"] = 12;
|
||||||
|
|
||||||
if (re2.indexIn(text) != -1) {
|
const QDate date(regexp.cap(static_cast<int>(MatchNames::YEARS)).toInt(),
|
||||||
QDate date(re2.cap(3).toInt(), monthmap[re2.cap(2)], re2.cap(1).toInt());
|
monthmap[regexp.cap(static_cast<int>(MatchNames::MONTHS))],
|
||||||
ret = QDateTime(date, QTime(re2.cap(4).toInt(), re2.cap(5).toInt(),
|
regexp.cap(static_cast<int>(MatchNames::DAYS)).toInt());
|
||||||
re2.cap(6).toInt()));
|
|
||||||
}
|
const QTime time(regexp.cap(static_cast<int>(MatchNames::HOURS)).toInt(),
|
||||||
return ret;
|
regexp.cap(static_cast<int>(MatchNames::MINUTES)).toInt(),
|
||||||
|
regexp.cap(static_cast<int>(MatchNames::SECONDS)).toInt());
|
||||||
|
|
||||||
|
return QDateTime (date, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* EnumToString(const QMetaObject& meta, const char* name, int value) {
|
const char* EnumToString(const QMetaObject& meta, const char* name, int value) {
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "core/utilities.h"
|
#include "core/utilities.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
TEST(UtilitiesTest, HmacFunctions) {
|
TEST(UtilitiesTest, HmacFunctions) {
|
||||||
|
@ -35,3 +36,12 @@ TEST(UtilitiesTest, HmacFunctions) {
|
||||||
bool result_sha256 = result_hash_sha256 == QString("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
|
bool result_sha256 = result_hash_sha256 == QString("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
|
||||||
EXPECT_TRUE(result_sha256);
|
EXPECT_TRUE(result_sha256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(UtilitiesTest, ParseRFC822DateTim) {
|
||||||
|
QDateTime result_DateTime = Utilities::ParseRFC822DateTime(QString("22 Feb 2008 00:16:17 GMT"));
|
||||||
|
EXPECT_TRUE(result_DateTime.isValid());
|
||||||
|
result_DateTime = Utilities::ParseRFC822DateTime(QString("Thu, 13 Dec 2012 13:27:52 +0000"));
|
||||||
|
EXPECT_TRUE(result_DateTime.isValid());
|
||||||
|
result_DateTime = Utilities::ParseRFC822DateTime(QString("Mon, 12 March 2012 20:00:00 +0100"));
|
||||||
|
EXPECT_TRUE(result_DateTime.isValid());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue