From c9e24c2283d0e1f0b3dd8c133ed1736663d1eac2 Mon Sep 17 00:00:00 2001 From: CoderTimZ Date: Wed, 6 Oct 2021 22:37:42 -0700 Subject: [PATCH] Display dates with the system date format --- Telegram/SourceFiles/api/api_authorizations.cpp | 2 +- Telegram/SourceFiles/core/application.cpp | 1 + Telegram/SourceFiles/data/data_peer.cpp | 2 +- Telegram/SourceFiles/data/data_peer_values.cpp | 4 ++-- Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp | 2 +- .../SourceFiles/history/history_inner_widget.cpp | 4 +++- .../history/view/history_view_list_widget.cpp | 4 +++- .../history/view/history_view_message.cpp | 2 +- .../media/view/media_view_overlay_widget.cpp | 2 +- Telegram/SourceFiles/settings.cpp | 1 + Telegram/SourceFiles/settings.h | 5 +++++ Telegram/SourceFiles/support/support_helper.cpp | 1 + Telegram/SourceFiles/ui/text/format_values.cpp | 13 ++++++++----- Telegram/SourceFiles/ui/text/format_values.h | 5 ++++- 14 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/api/api_authorizations.cpp b/Telegram/SourceFiles/api/api_authorizations.cpp index 4d2f93fccb..d8e997c365 100644 --- a/Telegram/SourceFiles/api/api_authorizations.cpp +++ b/Telegram/SourceFiles/api/api_authorizations.cpp @@ -82,7 +82,7 @@ Authorizations::Entry ParseEntry(const MTPDauthorization &data) { && lastDate.weekNumber() == nowDate.weekNumber()) { result.active = langDayOfWeek(lastDate); } else { - result.active = lastDate.toString(qsl("d.MM.yy")); + result.active = lastDate.toString(cDateFormat()); } } diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 8509c46d8e..4569411902 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -260,6 +260,7 @@ void Application::run() { DEBUG_LOG(("Application Info: inited...")); + cChangeDateFormat(QLocale::system().dateFormat(QLocale::ShortFormat)); cChangeTimeFormat(QLocale::system().timeFormat(QLocale::ShortFormat)); DEBUG_LOG(("Application Info: starting app...")); diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index b303fac02a..20203820ca 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -1078,7 +1078,7 @@ std::optional RestrictionError( auto restrictedUntil = channel->restrictedUntil(); if (restrictedUntil > 0 && !ChannelData::IsRestrictedForever(restrictedUntil)) { auto restrictedUntilDateTime = base::unixtime::parse(channel->restrictedUntil()); - auto date = restrictedUntilDateTime.toString(qsl("dd.MM.yy")); + auto date = restrictedUntilDateTime.toString(cDateFormat()); auto time = restrictedUntilDateTime.toString(cTimeFormat()); switch (restriction) { diff --git a/Telegram/SourceFiles/data/data_peer_values.cpp b/Telegram/SourceFiles/data/data_peer_values.cpp index 0195643586..fc38ba1ea7 100644 --- a/Telegram/SourceFiles/data/data_peer_values.cpp +++ b/Telegram/SourceFiles/data/data_peer_values.cpp @@ -386,7 +386,7 @@ QString OnlineText(TimeId online, TimeId now) { const auto onlineTime = onlineFull.time().toString(cTimeFormat()); return tr::lng_status_lastseen_yesterday(tr::now, lt_time, onlineTime); } - const auto date = onlineFull.date().toString(qsl("dd.MM.yy")); + const auto date = onlineFull.date().toString(cDateFormat()); return tr::lng_status_lastseen_date(tr::now, lt_date, date); } @@ -412,7 +412,7 @@ QString OnlineTextFull(not_null user, TimeId now) { const auto onlineTime = onlineFull.time().toString(cTimeFormat()); return tr::lng_status_lastseen_yesterday(tr::now, lt_time, onlineTime); } - const auto date = onlineFull.date().toString(qsl("dd.MM.yy")); + const auto date = onlineFull.date().toString(cDateFormat()); const auto time = onlineFull.time().toString(cTimeFormat()); return tr::lng_status_lastseen_date_time(tr::now, lt_date, date, lt_time, time); } diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp index 759492bc12..6f45622056 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_layout.cpp @@ -71,7 +71,7 @@ void PaintRowDate(Painter &p, QDateTime date, QRect &rectForName, bool active, b && lastDate.weekNumber() == nowDate.weekNumber()) { return langDayOfWeek(lastDate); } else { - return lastDate.toString(qsl("d.MM.yy")); + return lastDate.toString(cDateFormat()); } }(); PaintRowTopRight(p, dt, rectForName, active, selected); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index e0115563ca..5a3e384bb2 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2092,7 +2092,9 @@ TextForMimeData HistoryInner::getSelectedText() const { return TextForMimeData(); } - const auto timeFormat = qsl(", [dd.MM.yy hh:mm]\n"); + const auto timeFormat = QString(", [%1 %2]\n") + .arg(cDateFormat()) + .arg(cTimeFormat()); auto groups = base::flat_set>(); auto fullSize = 0; auto texts = base::flat_map(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 75fd3ca7c1..2edc1f44a9 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1765,7 +1765,9 @@ TextForMimeData ListWidget::getSelectedText() const { return _selectedText; } - const auto timeFormat = qsl(", [dd.MM.yy hh:mm]\n"); + const auto timeFormat = QString(", [%1 %2]\n") + .arg(cDateFormat()) + .arg(cTimeFormat()); auto groups = base::flat_set>(); auto fullSize = 0; auto texts = std::vectorimported) { const auto date = base::unixtime::parse(forwarded->originalDate); item->_timeText = date.toString( - u"d.MM.yy, "_q + cTimeFormat() + ' ' + cDateFormat() + u", "_q + cTimeFormat() + ' ' ) + tr::lng_imported(tr::now); } else { item->_timeText = dateTime().toString(cTimeFormat()); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index ceb12e3157..b63df68a27 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -810,7 +810,7 @@ void OverlayWidget::updateControls() { } return dNow; }(); - _dateText = Ui::FormatDateTime(d, cTimeFormat()); + _dateText = Ui::FormatDateTime(d, cDateFormat(), cTimeFormat()); if (!_fromName.isEmpty()) { _fromNameLabel.setText(st::mediaviewTextStyle, _fromName, Ui::NameTextOptions()); _nameNav = QRect(st::mediaviewTextLeft, height() - st::mediaviewTextTop, qMin(_fromNameLabel.maxWidth(), width() / 3), st::mediaviewFont->height); diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 5fff0f3217..7a8402b069 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -47,6 +47,7 @@ QByteArray gLocalSalt; int gScreenScale = style::kScaleAuto; int gConfigScale = style::kScaleAuto; +QString gDateFormat = qsl("dd.MM.yy"); QString gTimeFormat = qsl("hh:mm"); RecentStickerPreload gRecentStickersPreload; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index bc91f19cbe..3b3cf0e45b 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -82,6 +82,7 @@ DeclareSetting(bool, Quit); DeclareSetting(QByteArray, LocalSalt); DeclareSetting(int, ScreenScale); DeclareSetting(int, ConfigScale); +DeclareSetting(QString, DateFormat); DeclareSetting(QString, TimeFormat); class DocumentData; @@ -110,6 +111,10 @@ DeclareSetting(QString, StartUrl); DeclareSetting(int, OtherOnline); +inline void cChangeDateFormat(const QString &newFormat) { + if (!newFormat.isEmpty()) cSetDateFormat(newFormat); +} + inline void cChangeTimeFormat(const QString &newFormat) { if (!newFormat.isEmpty()) cSetTimeFormat(newFormat); } diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index c40e1180d7..7c11507a75 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -448,6 +448,7 @@ rpl::producer Helper::infoLabelValue( ) | rpl::map([](const Support::UserInfo &info) { const auto time = Ui::FormatDateTime( base::unixtime::parse(info.date), + cDateFormat(), cTimeFormat()); return info.author + ", " + time; }); diff --git a/Telegram/SourceFiles/ui/text/format_values.cpp b/Telegram/SourceFiles/ui/text/format_values.cpp index 71ecd14efd..a34cf46b07 100644 --- a/Telegram/SourceFiles/ui/text/format_values.cpp +++ b/Telegram/SourceFiles/ui/text/format_values.cpp @@ -79,25 +79,28 @@ QString FormatProgressText(qint64 ready, qint64 total) { total); } -QString FormatDateTime(QDateTime date, QString format) { +QString FormatDateTime( + QDateTime date, + QString dateFormat, + QString timeFormat) { const auto now = QDateTime::currentDateTime(); if (date.date() == now.date()) { return tr::lng_mediaview_today( tr::now, lt_time, - date.time().toString(format)); + date.time().toString(timeFormat)); } else if (date.date().addDays(1) == now.date()) { return tr::lng_mediaview_yesterday( tr::now, lt_time, - date.time().toString(format)); + date.time().toString(timeFormat)); } else { return tr::lng_mediaview_date_time( tr::now, lt_date, - date.date().toString(u"dd.MM.yy"_q), + date.date().toString(dateFormat), lt_time, - date.time().toString(format)); + date.time().toString(timeFormat)); } } diff --git a/Telegram/SourceFiles/ui/text/format_values.h b/Telegram/SourceFiles/ui/text/format_values.h index dca7dd90fc..56b0d1c780 100644 --- a/Telegram/SourceFiles/ui/text/format_values.h +++ b/Telegram/SourceFiles/ui/text/format_values.h @@ -16,7 +16,10 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2; [[nodiscard]] QString FormatSizeText(qint64 size); [[nodiscard]] QString FormatDownloadText(qint64 ready, qint64 total); [[nodiscard]] QString FormatProgressText(qint64 ready, qint64 total); -[[nodiscard]] QString FormatDateTime(QDateTime date, QString format); +[[nodiscard]] QString FormatDateTime( + QDateTime date, + QString dateFormat, + QString timeFormat); [[nodiscard]] QString FormatDurationText(qint64 duration); [[nodiscard]] QString FormatDurationWords(qint64 duration); [[nodiscard]] QString FormatDurationAndSizeText(qint64 duration, qint64 size);