Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/dde-dock/datetime/datetimewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,27 @@ void DatetimeWidget::updateDateTimeString()
m_dateTime = locale.toString(QDateTime::currentDateTime(), longDateFormat + " " + m_regionFormat->getLongTimeFormat());

QDateTime current = QDateTime::currentDateTime();
Comment on lines 144 to 146

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The midnight check uses a second QDateTime::currentDateTime() sample, while m_dateTime was formatted from an earlier sample. If the call crosses 01:00, m_dateTime contains the previous hour's 上午 text but isMidnightHour is false, so the tooltip remains 上午 12:59 while the taskbar label has already advanced to 01:00.

Triggers: When updateDateTimeString() runs during the instant at which the clock crosses from 00:59:59 to 01:00:00.

Suggested fix: Capture one QDateTime current before formatting m_dateTime and use that same value for the midnight check and all labels.

Suggested change
m_dateTime = locale.toString(QDateTime::currentDateTime(), longDateFormat + " " + m_regionFormat->getLongTimeFormat());
QDateTime current = QDateTime::currentDateTime();
QDateTime current = QDateTime::currentDateTime();
m_dateTime = locale.toString(current, longDateFormat + " " + m_regionFormat->getLongTimeFormat());

// 12 小时制下,0:00-0:59 时 Qt 将时段标记为"上午",与中文"凌晨"习惯不符,替换为"凌晨"
const bool isMidnightHour = !m_24HourFormat && current.time().hour() == 0;
if (isMidnightHour)
m_dateTime.replace(QStringLiteral("上午"), QStringLiteral("凌晨"));

const auto position = qApp->property(PROP_POSITION).value<Dock::Position>();
QString timeStr, dateString;
if (position == Dock::Bottom || position == Dock::Top) {
QString timeFormat = m_regionFormat->getShortTimeFormat();
timeStr = locale.toString(current, timeFormat);
if (isMidnightHour)
timeStr.replace(QStringLiteral("上午"), QStringLiteral("凌晨"));
dateString = locale.toString(current.date(), m_regionFormat->getShortDateFormat());

m_timeLabel->setText(timeStr);
m_dateLabel->setText(dateString);
} else {
if (!m_24HourFormat) {
QString apText = locale.toString(current, "AP");
if (isMidnightHour)
apText.replace(QStringLiteral("上午"), QStringLiteral("凌晨"));
m_apLabel->setText(apText);

QString timeFormat = m_regionFormat->getShortTimeFormat();
Expand Down
Loading