Skip to content

fix(datetime): show "凌晨" instead of "上午" for midnight hour in 12-hour format - #511

Closed
mhduiy wants to merge 1 commit into
masterfrom
fix/pms-278365-midnight-display
Closed

mhduiy wants to merge 1 commit into
masterfrom
fix/pms-278365-midnight-display

Conversation

@mhduiy

@mhduiy mhduiy commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

修复 PMS BUG-278365

问题

系统时间设置为 00:01(凌晨零点一分)时,任务栏时间在 12 小时制下显示为「上午 12:01」,与中文习惯不符。中文语境中「上午」通常指 6:00-12:00,0:00-5:59 应为「凌晨」,「上午 12:01」容易给用户造成误解。

根因

datetimewidget.cpp 的 updateDateTimeString() 方法直接使用 Qt QLocale::toString() 格式化时间。Qt 的 AM/PM 二分法在中文 locale 下将 hour 0(00:00-00:59)标记为「上午」并显示小时为「12」,输出「上午 12:01」。这是 Qt 标准 i18n 行为——Qt 仅有「上午/下午」两个时段,无「凌晨」概念。

修复方案

在 updateDateTimeString() 方法中,当 12 小时制且 hour 为 0 时,将格式化结果中的「上午」替换为「凌晨」:

  • 顶部/底部任务栏:timeStr 中「上午」→「凌晨」,显示「凌晨 12:01」
  • 左/右任务栏:apText(AM/PM 标签)中「上午」→「凌晨」
  • 提示文本(m_dateTime):同步替换,保持一致

影响面

  • 改动文件:datetimewidget.cpp(1 个方法,+8 行)
  • 仅影响 12 小时制下 hour 0(0:00-0:59)的时段文本显示
  • 不涉及接口变更、不影响 24 小时制、不影响日期显示
  • 非 Chinese locale 下「上午」不会出现在格式化结果中,替换为无操作(no-op)

PMS 链接

https://pms.uniontech.com/bug-view-278365.html

… format

Qt's QLocale AM/PM dichotomy marks hour 0 (00:00-00:59) as "上午" (AM)
in Chinese locale under 12-hour format, displaying "上午 12:01" which is
misleading since "上午" conventionally refers to 6:00-12:00 in Chinese.
Replace "上午" with "凌晨" when the current hour is 0 in 12-hour format.

Fixes: PMS BUG-278365
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions

Copy link
Copy Markdown

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议。
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

shuttle slave seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates datetime rendering so midnight displays as “凌晨 12:xx” rather than “上午 12:xx” in Chinese 12-hour mode, applying the replacement consistently to tooltip and taskbar layouts without changing other formats.

Flow diagram for midnight datetime label replacement

flowchart TD
    A[updateDateTimeString] --> B[QDateTime::currentDateTime]
    B --> C{!m_24HourFormat and hour == 0?}
    C -->|No| D[Keep locale-formatted text]
    C -->|Yes| E[QString::replace 上午, 凌晨]
    D --> F[Render tooltip and taskbar layout]
    E --> F
Loading

File-Level Changes

Change Details Files
Normalize the Chinese period label for midnight in 12-hour mode across all displayed datetime strings.
  • Detect 00:00–00:59 only when 12-hour mode is active.
  • Replace Qt’s Chinese “上午” label with “凌晨” in the tooltip, horizontal taskbar time, and vertical taskbar AM/PM label.
  • Leave 24-hour mode, other hours, dates, and non-Chinese locales unchanged.
plugins/dde-dock/datetime/datetimewidget.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="plugins/dde-dock/datetime/datetimewidget.cpp" line_range="144-146" />
<code_context>

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

</code_context>
<issue_to_address>
**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.

```suggestion
    QDateTime current = QDateTime::currentDateTime();
    m_dateTime = locale.toString(current, longDateFormat + " " + m_regionFormat->getLongTimeFormat());
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines 144 to 146
m_dateTime = locale.toString(QDateTime::currentDateTime(), longDateFormat + " " + m_regionFormat->getLongTimeFormat());

QDateTime current = QDateTime::currentDateTime();

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());

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 100 分,大于 70 分通过阈值,代码质量符合要求。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 检查语法错误和逻辑一致性


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 遵循代码规范和最佳实践


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 优化算法复杂度和资源使用


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 修复安全漏洞,加强输入验证


💡 改进建议代码示例

// 暂无代码示例

本报告由 AI 代码审查工具自动生成

@mhduiy
mhduiy marked this pull request as draft September 15, 2026 09:32
@mhduiy

mhduiy commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

AI 改动很不合理,改为草稿状态

@mhduiy

mhduiy commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

需求变更,无需修复

@mhduiy mhduiy closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants