Hell with date/times.
This commit is contained in:
parent
c753939fd7
commit
943d89c8e8
@ -96,8 +96,7 @@ FeedsModelStandardCategory *FeedsModelStandardCategory::loadFromRecord(const QSq
|
||||
category->setId(record.value(CAT_DB_ID_INDEX).toInt());
|
||||
category->setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
|
||||
category->setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
|
||||
category->setCreationDate(QDateTime::fromString(record.value(CAT_DB_DCREATED_INDEX).toString(),
|
||||
Qt::ISODate));
|
||||
category->setCreationDate(TextFactory::parseDateTime(record.value(CAT_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
|
||||
category->setIcon(IconFactory::fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray()));
|
||||
|
||||
return category;
|
||||
|
@ -32,8 +32,7 @@ FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord
|
||||
feed->setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
|
||||
feed->setId(record.value(FDS_DB_ID_INDEX).toInt());
|
||||
feed->setDescription(record.value(FDS_DB_DESCRIPTION_INDEX).toString());
|
||||
feed->setCreationDate(QDateTime::fromString(record.value(FDS_DB_DCREATED_INDEX).toString(),
|
||||
Qt::ISODate));
|
||||
feed->setCreationDate(TextFactory::parseDateTime(record.value(FDS_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
|
||||
feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
|
||||
feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString());
|
||||
feed->setUrl(record.value(FDS_DB_URL_INDEX).toString());
|
||||
@ -206,7 +205,7 @@ void FeedsModelStandardFeed::update() {
|
||||
|
||||
void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
||||
int feed_id = id(), message_id;
|
||||
QDateTime message_creation_date;
|
||||
qint64 message_creation_date;
|
||||
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection("FeedsModelStandardFeed");
|
||||
|
||||
// Prepare queries.
|
||||
@ -252,7 +251,7 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
||||
if (query_select.next()) {
|
||||
// Message with this title & url probably exists in current feed.
|
||||
message_id = query_select.value(0).toInt();
|
||||
message_creation_date = TextFactory::parseDateTime(query_select.value(2).toString());
|
||||
message_creation_date = query_select.value(2).value<qint64>();
|
||||
}
|
||||
else {
|
||||
message_id = -1;
|
||||
@ -266,15 +265,15 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
||||
query_insert.bindValue(":title", message.m_title);
|
||||
query_insert.bindValue(":url", message.m_url);
|
||||
query_insert.bindValue(":author", message.m_author);
|
||||
query_insert.bindValue(":date_created", message.m_created.toString(Qt::ISODate));
|
||||
query_insert.bindValue(":date_created", message.m_created.toMSecsSinceEpoch());
|
||||
query_insert.bindValue(":contents", message.m_contents);
|
||||
|
||||
query_insert.exec();
|
||||
query_insert.finish();
|
||||
}
|
||||
else if (message.m_createdFromFeed &&
|
||||
message_creation_date.isValid() &&
|
||||
message_creation_date > message.m_created) {
|
||||
message_creation_date != 0 &&
|
||||
message_creation_date > message.m_created.toMSecsSinceEpoch()) {
|
||||
qDebug("Message '%s' (id %d) was updated in the feed, updating too.",
|
||||
qPrintable(message.m_title),
|
||||
message_id);
|
||||
@ -288,7 +287,7 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
||||
query_update.bindValue(":title", message.m_title);
|
||||
query_update.bindValue(":url", message.m_url);
|
||||
query_update.bindValue(":author", message.m_author);
|
||||
query_update.bindValue(":date_created", message.m_created.toString(Qt::ISODate));
|
||||
query_update.bindValue(":date_created", message.m_created.toMSecsSinceEpoch());
|
||||
query_update.bindValue(":contents", message.m_contents);
|
||||
query_update.bindValue(":id", message_id);
|
||||
|
||||
|
@ -141,11 +141,8 @@ QVariant MessagesModel::data(const QModelIndex &index, int role) const {
|
||||
int index_column = index.column();
|
||||
|
||||
if (index_column == MSG_DB_DCREATED_INDEX) {
|
||||
// This column contains QDateTime properly stored in ISO format.
|
||||
// So that QDateTime::fromString(...) is okay here.
|
||||
return QDateTime::fromString(QSqlTableModel::data(index,
|
||||
role).toString(),
|
||||
Qt::ISODate).toLocalTime().toString(Qt::DefaultLocaleShortDate);
|
||||
return TextFactory::parseDateTime(QSqlTableModel::data(index,
|
||||
role).value<qint64>()).toLocalTime().toString(Qt::DefaultLocaleShortDate);
|
||||
}
|
||||
else if (index_column == MSG_DB_AUTHOR_INDEX) {
|
||||
QString author_name = QSqlTableModel::data(index, role).toString();
|
||||
|
@ -40,6 +40,20 @@ QDateTime TextFactory::parseDateTime(const QString &date_time) {
|
||||
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;
|
||||
}
|
||||
|
||||
QString TextFactory::shorten(const QString &input, int text_length_limit) {
|
||||
if (input.size() > text_length_limit) {
|
||||
return input.left(text_length_limit - ELLIPSIS_LENGTH) + QString(ELLIPSIS_LENGTH, '.');
|
||||
|
@ -14,8 +14,14 @@ class TextFactory {
|
||||
public:
|
||||
// Tries to parse input textual date/time representation.
|
||||
// Returns invalid date/time if processing fails.
|
||||
// NOTE: This method tries to always return time in UTC+00:00.
|
||||
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: On Windows UTC is known to be broken.
|
||||
static QDateTime parseDateTime(qint64 milis_from_epoch);
|
||||
|
||||
// Strips "<....>" (HTML, XML) tags from given text.
|
||||
static QString stripTags(QString text);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user