# 🌍 新日历功能：显示本地时间

**URL:** <https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608>\
**Category:** Announcements\
**Tags:** events\
**Created:** [2025年六月2日 20:54 UTC](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608 "2025-06-02T20:54:30Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2025年六月4日 23:03 UTC](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/21 "2025-06-04T23:03:33Z")

</div>

我们可以去掉开头的零吗？ 🤗

我认为这是一个很大的改进。

---

<div class="post-metadata">

**Author:** ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)\
**Post date:** [2025年六月6日 02:04 UTC](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/22 "2025-06-06T02:04:29Z")

</div>

> [@sam](#):
>
> 这对我来说毫无意义；它描述了一个从周日开始到周五结束的事件。

啊，抱歉，我没注意到你在说重复事件！

---

<div class="post-metadata">

**Author:** ![yuriy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yuriy/32/498097_2.png) [@yuriy](https://meta.discourse.org/u/yuriy)\
**Post date:** [2025年六月23日 09:46 UTC](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/24 "2025-06-23T09:46:35Z")

</div>

所以，我花了一段时间来处理这项任务，从上周开始，我看到它可以分为三个部分和一个问题：

1. 避免 _从 → 到_ 范围内的重复和冗余：
  - 当前年份，无时间（`00:00`）：
    - 同一周/月范围：`Mon, Oct 6 → Fri, Oct 10` || `Mon, Oct 6 → Mon, Oct 20`
    - 不同月份范围：`Mon, Oct 6 → Thu, Nov 6`

  - 当前年份，带时间：
    - 同一天范围：`Mon, Oct 6 12:00 AM → 1:00 AM`

  - 不同年份，无时间：`Mon, Oct 6 → Tue, Jan 6, 2026`

2. 根据勾选的复选框（在 OP 中）显示本地时间
3. 我注意到一些不一致之处，当我们显示 _两天前到今天之后一天_ 的日期范围时：
  - 带时间：`Yesterday/Today/Tomorrow 8:00 PM`
  - 无时间：`Monday...Sunday`

4. 有时时区会显示在日期时间末尾：`Today 2:00 PM → 4:00 PM (UTC)`。问题：在哪些情况下我们希望在括号中显示时区？

> <https://github.com/discourse/discourse/pull/33291/files#diff-2e077b606bd687089f93f9b13e8ee5c273827c8a9bcf96dd291a1d960ebbfd16R231-R236>

---

<div class="post-metadata">

**Author:** ![yuriy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yuriy/32/498097_2.png) [@yuriy](https://meta.discourse.org/u/yuriy)\
**Post date:** [2025年六月23日 13:46 UTC](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/25 "2025-06-23T13:46:34Z")

</div>

我有两个相关的 PR：

> <https://github.com/discourse/discourse-calendar/pull/745>
>
> This PR overhauls the way event dates are rendered by applying context-aware for…matting rules:
> \* Single-day events only show times when appropriate, hiding “12:00 AM” for events without \`endDate\`.
> \* Multi-day ranges omit redundant parts (e.g. for the current year) and include weekday/month/day when needed.
> 
> \### Tests added
> \* Weekday-only ranges (e.g. “Friday → Monday”)
> \* Same-week and same-month spans (omitting year)
> \* Cross-month and cross-year spans (including year where needed)
> \* \`Today/Yesterday/Tomorrow\` labels with time ranges
> \* Same-day events showing only time ￼
> 
> \### Impact
> \* Improves readability of event dates across the app
> \* Reduces visual noise by hiding redundant date/time fragments
> \* Ensures consistency with user expectations around relative dates
> 
> \### Things to clarify
> 
> \* Relative labels (\`Yesterday, Today, Tomorrow\`) replace literal dates for nearby days.
> \* Timezones are only shown when \`showLocalTime\` is toggled.
> 
> \### Discussion
> 
> https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/

> <https://github.com/discourse/discourse/pull/33291>

* * *

@nat，我把你拉进来，因为你几年前做过这个功能：

> <https://github.com/discourse/discourse/pull/18500>
>
> Essentially, introducing this change.
> 
> Saturday at 2:50 PM -\> Saturday at 4:38… PM 
> becomes 
> Saturday at 2:50 PM -\> 4:38 PM (Singapore)
> 
> Also, the displayed dates are shortened when the standalone date
> is within two days. So despite the 'from' and 'to' date being the 
> same day, it may show 'Saturday' for 'from', and the specific date 
> for the 'to'. This corrects the behaviour. So if the current date and 
> time is Thursday 5PM, the 'from' date below is within 2 days, but
> the 'to' date is not.
> 
> Saturday at 2:50 PM -\> 8 October 2022 at 9:38 PM 
> becomes
> Saturday at 2:50 PM -\> 9:38 PM

> <https://github.com/discourse/discourse/commit/1631394826e03073f99caa990811f261590d3257>

1. 在什么情况下，我们应该在 `from/to` 日期/时间后显示括号中的时区名称？

2. 显示的期望是什么：星期几名称 `Monday...Sunday` 还是 `Yesterday/Today/Tomorrow`？

---

<div class="post-metadata">

**Author:** ![yuriy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yuriy/32/498097_2.png) [@yuriy](https://meta.discourse.org/u/yuriy)\
**Post date:** [2025年六月23日 13:51 UTC](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/26 "2025-06-23T13:51:44Z")

</div>

我们已准备好合并第一个 PR。虽然不是最理想的，但修复边缘情况（如我[上一篇帖子](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/25?u=yaran)中所列）可能会随之而来。

> <https://github.com/discourse/discourse-calendar/pull/745>
>
> This PR overhauls the way event dates are rendered by applying context-aware for…matting rules:
> \* Single-day events only show times when appropriate, hiding “12:00 AM” for events without \`endDate\`.
> \* Multi-day ranges omit redundant parts (e.g. for the current year) and include weekday/month/day when needed.
> 
> \### Tests added
> \* Weekday-only ranges (e.g. “Friday → Monday”)
> \* Same-week and same-month spans (omitting year)
> \* Cross-month and cross-year spans (including year where needed)
> \* \`Today/Yesterday/Tomorrow\` labels with time ranges
> \* Same-day events showing only time ￼
> 
> \### Impact
> \* Improves readability of event dates across the app
> \* Reduces visual noise by hiding redundant date/time fragments
> \* Ensures consistency with user expectations around relative dates
> 
> \### Things to clarify
> 
> \* Relative labels (\`Yesterday, Today, Tomorrow\`) replace literal dates for nearby days.
> \* Timezones are only shown when \`showLocalTime\` is toggled.
> 
> \### Discussion
> 
> https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608/

[上一頁](https://meta.discourse.org/t/new-calendar-feature-show-local-time/368608.md?page=1)
