mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Replaced Qt format of dates in statistics with internal format.
This commit is contained in:
parent
27b284ef5b
commit
1a69975131
9 changed files with 110 additions and 47 deletions
|
@ -4337,6 +4337,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_stats_story_title" = "Story Statistic";
|
||||
"lng_stats_zoom_out" = "Zoom Out";
|
||||
|
||||
"lng_stats_day_month_year" = "{days_count} {month} {year}";
|
||||
"lng_stats_day_month" = "{days_count} {month}";
|
||||
"lng_stats_weekday_day_month_year" = "{day}, {days_count} {month} {year}";
|
||||
"lng_stats_weekday_day_month_time" = "{day}, {days_count} {month} {time}";
|
||||
|
||||
"lng_stats_overview_title" = "Overview";
|
||||
"lng_stats_overview_member_count" = "Followers";
|
||||
"lng_stats_overview_mean_view_count" = "Views Per Post";
|
||||
|
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "data/data_statistics_chart.h"
|
||||
|
||||
#include "statistics/statistics_format_values.h"
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QLocale>
|
||||
|
||||
|
@ -44,20 +46,18 @@ void StatisticalChart::measure() {
|
|||
const auto dateCount = int((end - start) / timeStep) + 10;
|
||||
daysLookup.reserve(dateCount);
|
||||
constexpr auto kOneDay = 3600 * 24 * 1000;
|
||||
const auto formatter = u"d MMM"_q;
|
||||
for (auto i = 0; i < dateCount; i++) {
|
||||
const auto r = (start + (i * timeStep)) / 1000;
|
||||
const auto dateTime = QDateTime::fromSecsSinceEpoch(r);
|
||||
if (timeStep == 1) {
|
||||
daysLookup.push_back(
|
||||
QString(((i < 10) ? u"0%1:00"_q : u"%1:00"_q).arg(i)));
|
||||
} else if (timeStep < kOneDay) {
|
||||
const auto dateTime = QDateTime::fromSecsSinceEpoch(r);
|
||||
daysLookup.push_back(u"%1:%2"_q
|
||||
.arg(dateTime.time().hour(), 2, 10, QChar('0'))
|
||||
.arg(dateTime.time().minute(), 2, 10, QChar('0')));
|
||||
} else {
|
||||
const auto date = dateTime.date();
|
||||
daysLookup.push_back(QLocale().toString(date, formatter));
|
||||
daysLookup.push_back(Statistic::LangDayMonth(r));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "settings/settings_common.h" // CreateLottieIcon.
|
||||
#include "statistics/chart_widget.h"
|
||||
#include "statistics/statistics_common.h"
|
||||
#include "statistics/statistics_format_values.h"
|
||||
#include "statistics/widgets/chart_header_widget.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/rect.h"
|
||||
|
@ -289,14 +290,11 @@ void AddHeader(
|
|||
header->setSubTitle({});
|
||||
return;
|
||||
}
|
||||
const auto formatter = u"d MMM yyyy"_q;
|
||||
const auto from = QDateTime::fromSecsSinceEpoch(startDate);
|
||||
const auto to = QDateTime::fromSecsSinceEpoch(endDate);
|
||||
header->setSubTitle(QLocale().toString(from.date(), formatter)
|
||||
header->setSubTitle(Statistic::LangDayMonthYear(startDate)
|
||||
+ ' '
|
||||
+ QChar(8212)
|
||||
+ ' '
|
||||
+ QLocale().toString(to.date(), formatter));
|
||||
+ Statistic::LangDayMonthYear(endDate));
|
||||
}
|
||||
|
||||
void FillOverview(
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/qt/qt_key_modifiers.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "statistics/chart_lines_filter_controller.h"
|
||||
#include "statistics/statistics_format_values.h"
|
||||
#include "statistics/view/abstract_chart_view.h"
|
||||
#include "statistics/view/chart_view_factory.h"
|
||||
#include "statistics/view/stack_chart_common.h"
|
||||
|
@ -72,22 +73,19 @@ void FillLineColorsByKey(Data::StatisticalChart &chartData) {
|
|||
if (leftTimestamp < kOneDay) {
|
||||
return {};
|
||||
}
|
||||
const auto formatter = u"d MMM yyyy"_q;
|
||||
const auto leftDateTime = QDateTime::fromSecsSinceEpoch(
|
||||
leftTimestamp / 1000);
|
||||
const auto leftText = QLocale().toString(leftDateTime.date(), formatter);
|
||||
const auto leftText = LangDayMonthYear(leftTimestamp / 1000);
|
||||
if ((xIndexMin == xIndexMax) && !chartData.weekFormat) {
|
||||
return leftText;
|
||||
} else {
|
||||
constexpr auto kSevenDays = 3600 * 24 * 7;
|
||||
const auto rightDateTime = QDateTime::fromSecsSinceEpoch(0
|
||||
const auto rightTimestamp = 0
|
||||
+ (chartData.x[xIndexMax] / 1000)
|
||||
+ (chartData.weekFormat ? kSevenDays : 0));
|
||||
+ (chartData.weekFormat ? kSevenDays : 0);
|
||||
return leftText
|
||||
+ ' '
|
||||
+ QChar(8212)
|
||||
+ ' '
|
||||
+ QLocale().toString(rightDateTime.date(), formatter);
|
||||
+ LangDayMonthYear(rightTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
68
Telegram/SourceFiles/statistics/statistics_format_values.cpp
Normal file
68
Telegram/SourceFiles/statistics/statistics_format_values.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "statistics/statistics_format_values.h"
|
||||
|
||||
#include "base/unixtime.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
||||
namespace Statistic {
|
||||
|
||||
QString LangDayMonthYear(crl::time seconds) {
|
||||
const auto date = base::unixtime::parse(seconds).date();
|
||||
return tr::lng_stats_day_month_year(
|
||||
tr::now,
|
||||
lt_days_count,
|
||||
QString::number(date.day()),
|
||||
lt_month,
|
||||
Lang::MonthSmall(date.month())(tr::now),
|
||||
lt_year,
|
||||
QString::number(date.year()));
|
||||
}
|
||||
|
||||
QString LangDayMonth(crl::time seconds) {
|
||||
const auto date = base::unixtime::parse(seconds).date();
|
||||
return tr::lng_stats_day_month(
|
||||
tr::now,
|
||||
lt_days_count,
|
||||
QString::number(date.day()),
|
||||
lt_month,
|
||||
Lang::MonthSmall(date.month())(tr::now));
|
||||
}
|
||||
|
||||
QString LangDetailedDayMonth(crl::time seconds) {
|
||||
const auto dateTime = base::unixtime::parse(seconds);
|
||||
if (dateTime.toUTC().time().hour() || dateTime.toUTC().time().minute()) {
|
||||
constexpr auto kOneDay = 3600 * 24;
|
||||
if (seconds < kOneDay) {
|
||||
return QLocale().toString(dateTime, QLocale::ShortFormat);
|
||||
}
|
||||
return tr::lng_stats_weekday_day_month_time(
|
||||
tr::now,
|
||||
lt_day,
|
||||
Lang::Weekday(dateTime.date().dayOfWeek())(tr::now),
|
||||
lt_days_count,
|
||||
QString::number(dateTime.date().day()),
|
||||
lt_month,
|
||||
Lang::MonthSmall(dateTime.date().month())(tr::now),
|
||||
lt_time,
|
||||
QLocale().toString(dateTime.time(), QLocale::ShortFormat));
|
||||
} else {
|
||||
return tr::lng_stats_weekday_day_month_year(
|
||||
tr::now,
|
||||
lt_day,
|
||||
Lang::Weekday(dateTime.date().dayOfWeek())(tr::now),
|
||||
lt_days_count,
|
||||
QString::number(dateTime.date().day()),
|
||||
lt_month,
|
||||
Lang::MonthSmall(dateTime.date().month())(tr::now),
|
||||
lt_year,
|
||||
QString::number(dateTime.date().year()));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Statistic
|
16
Telegram/SourceFiles/statistics/statistics_format_values.h
Normal file
16
Telegram/SourceFiles/statistics/statistics_format_values.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Statistic {
|
||||
|
||||
[[nodiscard]] QString LangDayMonthYear(crl::time seconds);
|
||||
[[nodiscard]] QString LangDayMonth(crl::time seconds);
|
||||
[[nodiscard]] QString LangDetailedDayMonth(crl::time seconds);
|
||||
|
||||
} // namespace Statistic
|
|
@ -7,9 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "statistics/widgets/point_details_widget.h"
|
||||
|
||||
#include "ui/cached_round_corners.h"
|
||||
#include "statistics/statistics_common.h"
|
||||
#include "statistics/statistics_format_values.h"
|
||||
#include "statistics/view/stack_linear_chart_common.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
|
@ -22,32 +23,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Statistic {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] QString FormatTimestamp(
|
||||
float64 timestamp,
|
||||
const QString &longFormat,
|
||||
const QString &shortFormat) {
|
||||
const auto dateTime = QDateTime::fromSecsSinceEpoch(timestamp / 1000);
|
||||
if (dateTime.toUTC().time().hour() || dateTime.toUTC().time().minute()) {
|
||||
return QLocale().toString(dateTime, longFormat);
|
||||
} else {
|
||||
return QLocale().toString(dateTime.date(), shortFormat);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] QString FormatWeek(float64 timestamp) {
|
||||
constexpr auto kSevenDays = 3600 * 24 * 7;
|
||||
const auto leftFormatter = u"d MMM"_q;
|
||||
const auto rightFormatter = u"d MMM yyyy"_q;
|
||||
timestamp /= 1000;
|
||||
return QLocale().toString(
|
||||
QDateTime::fromSecsSinceEpoch(timestamp).date(),
|
||||
leftFormatter)
|
||||
return LangDayMonth(timestamp)
|
||||
+ ' '
|
||||
+ QChar(8212)
|
||||
+ ' '
|
||||
+ QLocale().toString(
|
||||
QDateTime::fromSecsSinceEpoch(timestamp + kSevenDays).date(),
|
||||
rightFormatter);
|
||||
+ LangDayMonthYear(timestamp + kSevenDays);
|
||||
}
|
||||
|
||||
void PaintShadow(QPainter &p, int radius, const QRect &r) {
|
||||
|
@ -149,9 +132,7 @@ PointDetailsWidget::PointDetailsWidget(
|
|||
, _zoomEnabled(zoomEnabled)
|
||||
, _chartData(chartData)
|
||||
, _textStyle(st::statisticsDetailsPopupStyle)
|
||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle)
|
||||
, _longFormat(u"ddd, d MMM hh:mm"_q)
|
||||
, _shortFormat(u"ddd, d MMM yyyy"_q) {
|
||||
, _headerStyle(st::statisticsDetailsPopupHeaderStyle) {
|
||||
|
||||
if (zoomEnabled) {
|
||||
rpl::single(rpl::empty_value()) | rpl::then(
|
||||
|
@ -209,10 +190,7 @@ PointDetailsWidget::PointDetailsWidget(
|
|||
_headerStyle,
|
||||
_chartData.weekFormat
|
||||
? FormatWeek(_chartData.x.front())
|
||||
: FormatTimestamp(
|
||||
_chartData.x.front(),
|
||||
_longFormat,
|
||||
_shortFormat));
|
||||
: LangDetailedDayMonth(_chartData.x.front() / 1000));
|
||||
maxNameTextWidth = std::max(
|
||||
maxHeaderText.maxWidth()
|
||||
+ st::statisticsDetailsPopupPadding.left(),
|
||||
|
@ -278,7 +256,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
|
|||
? _chartData.getDayString(xIndex)
|
||||
: _chartData.weekFormat
|
||||
? FormatWeek(timestamp)
|
||||
: FormatTimestamp(timestamp, _longFormat, _shortFormat));
|
||||
: LangDetailedDayMonth(timestamp / 1000));
|
||||
}
|
||||
|
||||
_lines.clear();
|
||||
|
|
|
@ -46,8 +46,6 @@ private:
|
|||
const Data::StatisticalChart &_chartData;
|
||||
const style::TextStyle &_textStyle;
|
||||
const style::TextStyle &_headerStyle;
|
||||
const QString _longFormat;
|
||||
const QString _shortFormat;
|
||||
Ui::Text::String _header;
|
||||
|
||||
void invalidateCache();
|
||||
|
|
|
@ -186,6 +186,8 @@ PRIVATE
|
|||
statistics/statistics_common.h
|
||||
statistics/statistics_data_deserialize.cpp
|
||||
statistics/statistics_data_deserialize.h
|
||||
statistics/statistics_format_values.cpp
|
||||
statistics/statistics_format_values.h
|
||||
statistics/view/abstract_chart_view.cpp
|
||||
statistics/view/abstract_chart_view.h
|
||||
statistics/view/bar_chart_view.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue