summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-09-01 22:58:26 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:14 +0100
commit56e27ced2555fe6d2ae4644c391cc81a9b5bfd85 (patch)
tree29c026cef1770d9d5283c1e4227d8fbc309dbb0b /src
parentAdd avatar placeholder and scrollbar to qml timeline (diff)
downloadnheko-56e27ced2555fe6d2ae4644c391cc81a9b5bfd85.tar.xz
Format date (close to) the old way in qml timeline
Diffstat (limited to 'src')
-rw-r--r--src/timeline2/TimelineModel.cpp17
-rw-r--r--src/timeline2/TimelineModel.h2
2 files changed, 19 insertions, 0 deletions
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 <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); +} 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 <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);