- Improved date handling in RSS

This commit is contained in:
Christophe Dumez 2010-01-23 16:16:42 +00:00
parent 8ed0e58d63
commit 2ce375d8eb
3 changed files with 10 additions and 10 deletions

View file

@ -37,7 +37,7 @@ public:
}
~FeedList() {
delete unread_item;
//delete unread_item;
}
void itemAdded(QTreeWidgetItem *item, RssFile* file) {

View file

@ -137,7 +137,7 @@ protected:
QDateTime parseDate(const QString &string) {
QString str = string.trimmed();
if (str.isEmpty())
return QDateTime();
return QDateTime::currentDateTime();
int nyear = 6; // indexes within string to values
int nmonth = 4;
@ -155,12 +155,12 @@ protected:
bool h1 = (parts[3] == QLatin1String("-"));
bool h2 = (parts[5] == QLatin1String("-"));
if (h1 != h2)
return QDateTime();
return QDateTime::currentDateTime();
} else {
// Check for the obsolete form "Wdy Mon DD HH:MM:SS YYYY"
rx = QRegExp("^([A-Z][a-z]+)\\s+(\\S+)\\s+(\\d\\d)\\s+(\\d\\d):(\\d\\d):(\\d\\d)\\s+(\\d\\d\\d\\d)$");
if (str.indexOf(rx))
return QDateTime();
return QDateTime::currentDateTime();
nyear = 7;
nmonth = 2;
nday = 3;
@ -176,12 +176,12 @@ protected:
int hour = parts[nhour].toInt(&ok[2]);
int minute = parts[nmin].toInt(&ok[3]);
if (!ok[0] || !ok[1] || !ok[2] || !ok[3])
return QDateTime();
return QDateTime::currentDateTime();
int second = 0;
if (!parts[nsec].isEmpty()) {
second = parts[nsec].toInt(&ok[0]);
if (!ok[0])
return QDateTime();
return QDateTime::currentDateTime();
}
bool leapSecond = (second == 60);
if (leapSecond)
@ -247,11 +247,11 @@ protected:
}
QDate qdate(year, month+1, day); // convert date, and check for out-of-range
if (!qdate.isValid())
return QDateTime();
return QDateTime::currentDateTime();
QDateTime result(qdate, QTime(hour, minute, second));
if (!result.isValid()
|| (dayOfWeek >= 0 && result.date().dayOfWeek() != dayOfWeek+1))
return QDateTime(); // invalid date/time, or weekday doesn't correspond with date
return QDateTime::currentDateTime(); // invalid date/time, or weekday doesn't correspond with date
if (!offset) {
result.setTimeSpec(Qt::UTC);
}
@ -259,7 +259,7 @@ protected:
// Validate a leap second time. Leap seconds are inserted after 23:59:59 UTC.
// Convert the time to UTC and check that it is 00:00:00.
if ((hour*3600 + minute*60 + 60 - offset + 86400*5) % 86400) // (max abs(offset) is 100 hours)
return QDateTime(); // the time isn't the last second of the day
return QDateTime::currentDateTime(); // the time isn't the last second of the day
}
return result;
}

View file

@ -475,7 +475,7 @@ void RSSImp::refreshTextBrowser() {
html += "<div style='border: 2px solid red; margin-left: 5px; margin-right: 5px; margin-bottom: 5px;'>";
html += "<div style='background-color: #678db2; font-weight: bold; color: #fff;'>"+article->getTitle() + "</div>";
if(article->getDate().isValid()) {
html += "<div style='background-color: #efefef;'><b>"+tr("Date: ")+"</b>"+article->getDate().toString()+"</div>";
html += "<div style='background-color: #efefef;'><b>"+tr("Date: ")+"</b>"+article->getDate().toLocalTime().toString(Qt::SystemLocaleLongDate)+"</div>";
}
if(!article->getAuthor().isEmpty()) {
html += "<div style='background-color: #efefef;'><b>"+tr("Author: ")+"</b>"+article->getAuthor()+"</div>";