Skip to content
Snippets Groups Projects
Commit 56e27ced authored by Nicolas Werner's avatar Nicolas Werner
Browse files

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

parent ccedbde3
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment