Skip to content

fix: Information time display in English#1459

Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
JWWTSL:master
Mar 2, 2026
Merged

fix: Information time display in English#1459
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL
Copy link
Contributor

@JWWTSL JWWTSL commented Feb 28, 2026

log: Optimised display logic

pms: bug-350589

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @JWWTSL, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要是为了解决日期时间显示的本地化问题。下面是对这段 diff 的详细审查和改进建议:

1. 代码逻辑审查

优点:

  • 修改后的代码使用了 QLocale::system() 来格式化时间字符串,这确保了日期显示会遵循用户系统的区域设置(如语言、国家/地区),这是一个很好的本地化实践。
  • 对于 2-7 天前的通知,使用 "ddd hh:mm" 格式,显示星期几和具体时间,逻辑合理。

潜在问题:

  • else 分支中,使用了 QLocale::system().dateFormat(QLocale::ShortFormat),这会根据系统设置返回短日期格式字符串(如 "M/d/yy" 或 "yyyy/M/d"),但并未包含时间信息。如果 time 变量包含具体的时间部分,这部分信息将会丢失。建议确认此处是否需要显示时间。

2. 代码质量审查

建议:

  • 代码风格统一:建议统一使用 QLocale::system().toString() 的方式来格式化时间,而不是混用 QLocale::system().dateFormat()time.toString()
  • 添加注释:建议在条件分支处添加注释,说明不同时间范围的显示逻辑,提高代码可读性。

3. 代码性能审查

分析:

  • QLocale::system() 在每次调用时可能会查询系统设置,虽然开销不大,但如果 updateTime() 被频繁调用(例如每秒更新一次),可能会产生不必要的性能开销。
  • 建议在类初始化时缓存 QLocale::system() 对象,或使用静态局部变量缓存。

4. 代码安全审查

分析:

  • 此处修改不涉及内存安全或输入验证问题。
  • 使用 Qt 的本地化 API 是安全的,Qt 会处理不同区域设置下的格式化问题。

5. 改进后的代码建议

void AppNotifyItem::updateTime()
{
    // 缓存系统区域设置,避免重复查询
    static const QLocale systemLocale = QLocale::system();
    
    // ... (之前的代码保持不变)
    
    } else if (elapsedDay >= 2 && elapsedDay < 7) {
        // 显示星期几和时间 (例如: "周一 14:30")
        ret = systemLocale.toString(time, "ddd hh:mm");
    } else {
        // 显示短日期格式 (例如: "2023/12/25")
        // 注意:如果需要显示时间,应修改格式字符串
        ret = systemLocale.toString(time, systemLocale.dateFormat(QLocale::ShortFormat));
    }
}

6. 其他建议

  1. 时间格式一致性:检查整个项目中时间显示的格式是否一致,特别是 12/24 小时制的处理。
  2. 国际化测试:建议在不同区域设置下测试日期显示效果,确保格式正确。
  3. 时间精度:确认是否需要显示秒数,如果不需要,可以明确在格式字符串中排除(如 "hh:mm" 而不是 "hh:mm:ss")。

这些改进可以提高代码的可读性、性能和可维护性,同时确保在不同区域设置下都能正确显示日期时间。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, JWWTSL

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

@18202781743
Copy link
Contributor

copyright的时间改一下,

@JWWTSL
Copy link
Contributor Author

JWWTSL commented Mar 2, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 2, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 7417fea into linuxdeepin:master Mar 2, 2026
9 of 11 checks passed
JWWTSL and others added 2 commits March 4, 2026 17:14
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.

3 participants