# 时间线显示日期时出现 off-by-one 错误？

**URL:** https://meta.discourse.org/t/off-by-one-error-showing-the-date-in-timeline-ago/126119
**Category:** UX
**Created:** [2019年八月18日 22:26 UTC](https://meta.discourse.org/t/off-by-one-error-showing-the-date-in-timeline-ago/126119 "2019-08-18T22:26:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![danielcompton](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielcompton/32/153375_2.png) [@danielcompton](https://meta.discourse.org/u/danielcompton)
#### Post date: [2019年八月18日 22:26 UTC](https://meta.discourse.org/t/off-by-one-error-showing-the-date-in-timeline-ago/126119/1 "2019-08-18T22:26:01Z")

</div>

当我查看 `https://meta.discourse.org/t/admin-actions-goes-behind-the-titlebar/118649`（作为新用户我无法直接发布链接）（或许多其他 Discourse 帖子）时，我看到以下内容：

 ![Screenshot%20of%20Safari%20copy](https://global.discourse-cdn.com/meta/original/3X/f/5/f5cd4d0bb053df4728af8fd10c220e2a763ab045.png)

**时间轴中的开始日期是 5 月 25 日，但在时间轴组件中当位置为 1/5 时显示的日期却是 5 月 26 日。**

我的电脑（macOS 10.14.6，Safari 12.1.2）的时区设置为 `Pacific/Auckland`。当我将电脑时区切换为 `America/Los_Angeles` 时，出现了相同的问题，但所有日期都向后推移了一天。

`timeline-ago` 中的日期是在 [discourse/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 at 9a17b196365a1f9a5e88a0f8a36e2e35c56b39bc · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/9a17b196365a1f9a5e88a0f8a36e2e35c56b39bc/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6#L84) 处设置的，并使用 [`timelineDate`](https://github.com/discourse/discourse/blob/9a17b196365a1f9a5e88a0f8a36e2e35c56b39bc/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6#L53-L59) 来格式化日期。该值用于设置 `start-date` 和 `now-date`，因此不太可能是问题的根源。

通过阅读代码，`position`（第 151-154 行）看起来\_可能\_是导致问题的原因，但我也不确定，因为我刚接触 Discourse 代码库和 Ember。

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2019年八月18日 23:46 UTC](https://meta.discourse.org/t/off-by-one-error-showing-the-date-in-timeline-ago/126119/2 "2019-08-18T23:46:20Z")

</div>

该主题已严重过时并被删除，但首帖的日期为

`<span title="May 24, 2019 11:14 pm" data-time="1558764857214" data-format="tiny" class="relative-date">5 月 24 日</span>`

---

<div class="post-metadata">

### Author: ![danielcompton](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/danielcompton/32/153375_2.png) [@danielcompton](https://meta.discourse.org/u/danielcompton)
#### Post date: [2019年八月19日 00:09 UTC](https://meta.discourse.org/t/off-by-one-error-showing-the-date-in-timeline-ago/126119/3 "2019-08-19T00:09:09Z")

</div>

我想那是一个本地化的时间戳？我看到了

`<span title="May 25, 2019 6:14 pm" data-time="1558764857214" data-format="tiny" class="relative-date">May 25</span>`

我已编辑帖子，使问题更清晰。
