Conversation
… 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
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
CLA Assistant Lite bot: 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. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates 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 replacementflowchart 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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| m_dateTime = locale.toString(QDateTime::currentDateTime(), longDateFormat + " " + m_regionFormat->getLongTimeFormat()); | ||
|
|
||
| QDateTime current = QDateTime::currentDateTime(); |
There was a problem hiding this comment.
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.
| 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 pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 检查语法错误和逻辑一致性 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 遵循代码规范和最佳实践 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 优化算法复杂度和资源使用 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 修复安全漏洞,加强输入验证 💡 改进建议代码示例// 暂无代码示例本报告由 AI 代码审查工具自动生成 |
|
AI 改动很不合理,改为草稿状态 |
|
需求变更,无需修复 |
修复 PMS BUG-278365
问题
系统时间设置为 00:01(凌晨零点一分)时,任务栏时间在 12 小时制下显示为「上午 12:01」,与中文习惯不符。中文语境中「上午」通常指 6:00-12:00,0:00-5:59 应为「凌晨」,「上午 12:01」容易给用户造成误解。
根因
datetimewidget.cpp的updateDateTimeString()方法直接使用 QtQLocale::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 标签)中「上午」→「凌晨」影响面
datetimewidget.cpp(1 个方法,+8 行)PMS 链接
https://pms.uniontech.com/bug-view-278365.html