diff --git a/resources/misc/db_init.sql b/resources/misc/db_init.sql index c3333e177..968b27f67 100644 --- a/resources/misc/db_init.sql +++ b/resources/misc/db_init.sql @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS Categories ( parent_id INTEGER NOT NULL, title TEXT NOT NULL UNIQUE CHECK (title != ''), description TEXT, - date_created TEXT NOT NULL CHECK (date_created != ''), + date_created INTEGER NOT NULL CHECK (date_created != 0), icon BLOB, type INTEGER NOT NULL, @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS Feeds ( id INTEGER PRIMARY KEY, title TEXT NOT NULL CHECK (title != ''), description TEXT, - date_created TEXT NOT NULL CHECK (date_created != ''), + date_created INTEGER NOT NULL CHECK (date_created != 0), icon BLOB, category INTEGER NOT NULL CHECK (category >= -1), encoding TEXT NOT NULL CHECK (encoding != ''), @@ -58,24 +58,24 @@ CREATE TABLE IF NOT EXISTS Messages ( title TEXT NOT NULL CHECK (title != ''), url TEXT, author TEXT, - date_created TEXT NOT NULL CHECK (date_created != ''), + date_created INTEGER NOT NULL CHECK (date_created != 0), contents TEXT, FOREIGN KEY (feed) REFERENCES Feeds (id) ); -- ! -INSERT INTO Categories (id, parent_id, title, description, date_created, type) VALUES (1, -1, 'Linux', 'Collections of GNU/Linux-related feeds.', '2013-12-20T08:00:00-05:00', 0); +INSERT INTO Categories (id, parent_id, title, description, date_created, type) VALUES (1, -1, 'Linux', 'Collections of GNU/Linux-related feeds.', 1388678961000, 0); -- ! -INSERT INTO Categories (id, parent_id, title, description, date_created, type) VALUES (2, -1, 'RSS Guard', 'News and updates on RSS Guard.', '2013-12-20T08:00:00-05:00', 0); +INSERT INTO Categories (id, parent_id, title, description, date_created, type) VALUES (2, -1, 'RSS Guard', 'News and updates on RSS Guard.', 1388678961000, 0); -- ! -INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Linux Today', 'Linux Today - Linux News on Internet Time.', '2013-12-20T08:00:00-05:00', 1, 'UTF-8', 'http://feeds.feedburner.com/linuxtoday/linux?format=xml', 1); +INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Linux Today', 'Linux Today - Linux News on Internet Time.', 1388678961000, 1, 'UTF-8', 'http://feeds.feedburner.com/linuxtoday/linux?format=xml', 1); -- ! -INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LinuxInsider', 'LinuxInsider: Linux News & Information from Around the World.', '2013-12-20T08:00:00-05:00', 1, 'UTF-8', 'http://www.linuxinsider.com/perl/syndication/rssfull.pl', 2); +INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LinuxInsider', 'LinuxInsider: Linux News & Information from Around the World.', 1388678961000, 1, 'UTF-8', 'http://www.linuxinsider.com/perl/syndication/rssfull.pl', 2); -- ! -INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LXer: Linux News', 'The world is talking about GNU/Linux and Free/Open Source Software.', '2013-12-20T08:00:00-05:00', 1, 'UTF-8', 'http://lxer.com/module/newswire/headlines.rss', 2); +INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('LXer: Linux News', 'The world is talking about GNU/Linux and Free/Open Source Software.', 1388678961000, 1, 'UTF-8', 'http://lxer.com/module/newswire/headlines.rss', 2); -- ! -INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Recent Commits', 'Recent commits for RSS Guard project.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/commits/master.atom', 3); +INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Recent Commits', 'Recent commits for RSS Guard project.', 1388678961000, 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/commits/master.atom', 3); -- ! -INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Releases', 'Releases for RSS Guard.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/releases.atom', 3); +INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Releases', 'Releases for RSS Guard.', 1388678961000, 2, 'UTF-8', 'https://github.com/martinrotter/rssguard/releases.atom', 3); -- ! -INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Author''s Activity', 'RSS Guard author public activity overview.', '2013-12-20T08:00:00-05:00', 2, 'UTF-8', 'https://github.com/martinrotter.atom', 3); \ No newline at end of file +INSERT INTO Feeds (title, description, date_created, category, encoding, url, type) VALUES ('Author''s Activity', 'RSS Guard author public activity overview.', 1388678961000, 2, 'UTF-8', 'https://github.com/martinrotter.atom', 3); \ No newline at end of file diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index ab4a1af02..5a0bc3b0b 100644 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -97,7 +97,7 @@ Message MessagesModel::messageAt(int row_index) const { message.m_contents = rec.value(MSG_DB_CONTENTS_INDEX).toString(); message.m_title = rec.value(MSG_DB_TITLE_INDEX).toString(); message.m_url = rec.value(MSG_DB_URL_INDEX).toString(); - message.m_created = TextFactory::parseDateTime(rec.value(MSG_DB_DCREATED_INDEX).toString()); + message.m_created = TextFactory::parseDateTime(rec.value(MSG_DB_DCREATED_INDEX).value()); return message; } diff --git a/src/core/textfactory.cpp b/src/core/textfactory.cpp index 24eaac815..27a2dcbd3 100644 --- a/src/core/textfactory.cpp +++ b/src/core/textfactory.cpp @@ -18,39 +18,76 @@ QDateTime TextFactory::parseDateTime(const QString &date_time) { QString temp; QLocale locale(QLocale::C); QStringList date_patterns; + QTime time_zone_offset; + bool positive_time_zone_offset = false; + date_patterns << "yyyy-MM-ddTHH:mm:ss" << "MMM dd yyyy hh:mm:ss" << "MMM d yyyy hh:mm:ss" << "ddd, dd MMM yyyy HH:mm:ss" << "dd MMM yyyy" << "yyyy-MM-dd HH:mm:ss.z" << "yyyy-MM-dd" << - "YYYY" << "YYYY-MM" << "YYYY-MM-DD" << "YYYY-MM-DDThh:mmTZD" << - "YYYY-MM-DDThh:mm:ssTZD"; + "YYYY" << "YYYY-MM" << "YYYY-MM-DD" << "YYYY-MM-DDThh:mm" << + "YYYY-MM-DDThh:mm:ss"; + + // Check if last part of date is time zone offset, + // represented as [+|-]hh:mm. + int date_length = date.size(); + + if (date_length > 6) { + char zone_sign = date.at(date_length - 6).toLatin1(); + + switch (zone_sign) { + case '+': + // Positive time zone offset detected. + positive_time_zone_offset = true; + time_zone_offset = QTime::fromString(date.right(5), + "hh:mm"); + + date.chop(6); + break; + + case '-': + // Negative time zone offset detected. + time_zone_offset = QTime::fromString(date.right(5), + "hh:mm"); + + date.chop(6); + break; + + default: + // No time zone offset. + break; + } + } // Iterate over patterns and check if input date/time matches the pattern. foreach (const QString &pattern, date_patterns) { temp = date.left(pattern.size()); dt = locale.toDateTime(temp, pattern); + if (dt.isValid()) { dt.setTimeSpec(Qt::UTC); - return dt; + + if (time_zone_offset.isValid()) { + if (positive_time_zone_offset) { + return dt.addSecs(QTime(0, 0, 0, 0).secsTo(time_zone_offset)); + } + else { + int secs = QTime(0, 0, 0, 0).secsTo(time_zone_offset); + + return dt.addSecs(- QTime(0, 0, 0, 0).secsTo(time_zone_offset)); + } + } + else { + return dt; + } } } - // TODO: ISO time zone offsets are not read now, problem. - // Parsing failed, return invalid datetime. return QDateTime(); } QDateTime TextFactory::parseDateTime(qint64 milis_from_epoch) { QDateTime converted = QDateTime::fromMSecsSinceEpoch(milis_from_epoch); - - // TODO: tadle funkce nahore fromMSec.. by mela vracet cas v UTC - // tedy timespec Qt::UTC, ale na windows vraci local time. - // overit co to vraci na linuxu a podle toho - // prenastavit zobrazovani datumu v messagesmodelu::data (delani - // nebo nedelani konverze .toLocalTime(). - // mozna taky toString() udela konverzi za me. - // vsude je pouzito prozatim toLocalTime() - //converted.setTimeSpec(Qt::UTC); return converted; } diff --git a/src/core/textfactory.h b/src/core/textfactory.h index eefd41c92..f79b4961c 100644 --- a/src/core/textfactory.h +++ b/src/core/textfactory.h @@ -18,7 +18,8 @@ class TextFactory { static QDateTime parseDateTime(const QString &date_time); // Converts 1970-epoch miliseconds to date/time. - // NOTE: This method returns date/time in UTC+00:00. + // NOTE: This method returns date/time local-time + // which is calculated from the system settings. // NOTE: On Windows UTC is known to be broken. static QDateTime parseDateTime(qint64 milis_from_epoch); diff --git a/src/gui/formcategorydetails.cpp b/src/gui/formcategorydetails.cpp index 1984324aa..547e453dd 100644 --- a/src/gui/formcategorydetails.cpp +++ b/src/gui/formcategorydetails.cpp @@ -28,7 +28,7 @@ FormCategoryDetails::~FormCategoryDetails() { void FormCategoryDetails::setEditableCategory(FeedsModelCategory *editable_category) { m_editableCategory = editable_category; - // TODO: Setup the dialog according to new category. + // TODO: Setup the dialog according to the category. // so remove this category from category combobox!! m_ui->m_txtTitle->setText(editable_category->title()); m_ui->m_txtDescription->setText(editable_category->description());