mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
Format date (close to) the old way in qml timeline
This commit is contained in:
parent
ccedbde38b
commit
56e27ced25
3 changed files with 20 additions and 1 deletions
|
@ -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…
Reference in a new issue