Format date (close to) the old way in qml timeline

pull/91/head
Nicolas Werner 5 years ago
parent ccedbde38b
commit 56e27ced25
  1. 2
      resources/qml/TimelineView.qml
  2. 17
      src/timeline2/TimelineModel.cpp
  3. 2
      src/timeline2/TimelineModel.h

@ -104,7 +104,7 @@ Rectangle {
id: dateBubble
anchors.horizontalCenter: parent.horizontalCenter
visible: section.includes(" ")
text: Qt.formatDate(new Date(Number(section.split(" ")[1])))
text: chat.model.formatDateSeparator(new Date(Number(section.split(" ")[1])))
height: contentHeight * 1.2
width: contentWidth * 1.2
horizontalAlignment: Text.AlignHCenter

@ -1,5 +1,7 @@
#include "TimelineModel.h"
#include <QRegularExpression>
#include "Logging.h"
#include "Utils.h"
@ -196,3 +198,18 @@ TimelineModel::displayName(QString id) const
{
return Cache::displayName(room_id_, id);
}
QString
TimelineModel::formatDateSeparator(QDate date) const
{
auto now = QDateTime::currentDateTime();
QString fmt = QLocale::system().dateFormat(QLocale::LongFormat);
if (now.date().year() == date.year()) {
QRegularExpression rx("[^a-zA-Z]*y+[^a-zA-Z]*");
fmt = fmt.remove(rx);
}
return date.toString(fmt);
}

@ -2,6 +2,7 @@
#include <QAbstractListModel>
#include <QColor>
#include <QDate>
#include <QHash>
#include <mtx/responses.hpp>
@ -30,6 +31,7 @@ public:
Q_INVOKABLE QColor userColor(QString id, QColor background);
Q_INVOKABLE QString displayName(QString id) const;
Q_INVOKABLE QString formatDateSeparator(QDate date) const;
void addEvents(const mtx::responses::Timeline &events);

Loading…
Cancel
Save