diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 3697b37b..bab1d932 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -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 diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index d7eb02d0..6f212833 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -1,5 +1,7 @@ #include "TimelineModel.h" +#include + #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); +} diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index 9dfb4401..e2c7b73a 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -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);