# Anniversaries: date off by one

**URL:** https://meta.discourse.org/t/anniversaries-date-off-by-one/64140
**Category:** Bug
**Created:** [2017年六月8日 00:00 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140 "2017-06-08T00:00:11Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![barryvan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barryvan/32/82635_2.png) [@barryvan](https://meta.discourse.org/u/barryvan)
#### Post date: [2017年六月8日 00:00 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/1 "2017-06-08T00:00:11Z")

</div>

I was very pleased this morning to see that it’s my cakeday (on the forum I administer):

 ![](https://global.discourse-cdn.com/meta/original/3X/a/9/a93c6ef06d021353ab56bc658d40b0493d0ac4fd.png)

And out of curiosity I went to see who else’s cakeday was nearby. Strangely, though, the anniversaries page seems to be a day in the past:

 ![](https://global.discourse-cdn.com/meta/original/3X/d/9/d95e1c4eacc70cc8b5247fb0cc0e521d6ff662a7.png)

Could it be because I’m in GMT+8?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2017年六月8日 04:37 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/2 "2017-06-08T04:37:54Z")

</div>

That’s what I think.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年六月8日 04:44 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/3 "2017-06-08T04:44:08Z")

</div>

> [@barryvan](#):
>
> Could it be because I’m in GMT+8?

> [@pfaffman](#):
>
> That’s what I think.

Given that Discourse localizes the times it shows you everywhere else in the UI, I feel this is still a “bug” and should be fixed.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2017年六月8日 04:45 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/4 "2017-06-08T04:45:45Z")

</div>

So there are 24+ different cake day sets? That seems crazy.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年六月8日 04:48 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/5 "2017-06-08T04:48:37Z")

</div>

> [@pfaffman](#):
>
> So there are 24+ different cake day sets?

That’s one way to look at it I guess. But I’m assuming the users are queried on page load, so there’s really only “one” set at a time.

Here’s a better example. The post you just made shows up for me as “June 8, 2017 12:45 AM”. If I was to fly across the country to California, I’d expect that post to show as “June 7, 2017 9:45 PM”.

---

<div class="post-metadata">

### Author: ![barryvan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barryvan/32/82635_2.png) [@barryvan](https://meta.discourse.org/u/barryvan)
#### Post date: [2017年六月9日 00:13 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/6 "2017-06-09T00:13:36Z")

</div>

…and I just earned the “anniversary” badge this morning. This does _feel_ like a bug to me.

Could it be mitigated by simply changing the timezone of the server to something more applicable for my community? We’re (mainly) in Australia, so processing everything as, say, GMT+8 or GMT+10 would make this all feel less odd.

Not a major issue, of course. 😉

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [2017年六月9日 05:42 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/7 "2017-06-09T05:42:00Z")

</div>

Since the server doesn’t know a user’s time zone, maybe the easiest fix for this would be to award the badge one day later? For some, that will mean they get it late, but that will probably not be experienced as a bug as much as an early award is.

Another option might be to simply specify in the UI that these times are based on the server’s time zone.

---

<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: [2020年一月10日 04:31 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/9 "2020-01-10T04:31:13Z")

</div>

> [@barryvan](#):
>
> 是否可以通过简单地将服务器时区更改为更适合我所在社区的时区来缓解这个问题？我们（主要）在澳大利亚，所以将所有内容都按 GMT+8 或 GMT+10 处理，会让这一切感觉不那么奇怪。

我认为，在一个高度本地化的社区中，应该允许为 Discourse 的“蛋糕日”指定时区。更改服务器时区并不是我们真正能做的事情。

这确实是个棘手的问题，即使我们现在允许用户指定“时区”，我也不确定该如何解决。

假设你在澳大利亚注册了一个论坛，时间是`2019 年 1 月 2 日上午 8 点`。

- 根据“蛋糕日”计算，你的 1 周年纪念日将是`2010 年 1 月 1 日`。

- 当你在 1 月 2 日上午 8 点访问纪念日页面时，你会看到来自`2010 年 1 月 1 日`的纪念日，而不是 2 日。

我想我们这里的要求是，使用用户在个人资料中定义的“本地”时区来处理相关事宜。

意思是：

- 你的 1 周年纪念日应该是`2019 年 1 月 1 日`，因为你的用户个人资料中的本地时区是澳大利亚。

- 当你在 2 日访问纪念日页面时，你应该看到 2 日。

* * *

目前，我支持一个简单的修复方案：在渲染纪念日页面时，查看当前用户的本地时区，并针对已登录用户的情况，使用该日期而不是 UTC 当前日期。这应该是一个很容易的改动，可能只需要两行代码。

@techAPJ 你能处理一下吗？

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [2020年一月16日 12:53 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/11 "2020-01-16T12:53:48Z")

</div>

我相信 @tgxworld 已经通过以下方式修复了这个问题，以考虑时区偏移：

> <https://github.com/discourse/discourse-cakeday/commit/c6fd1f08545e09d012a558494bddd368a5d4864d#diff-edec1c4b3a2ef7541c47f9f05c59fe41>

以及

> <https://github.com/discourse/discourse-cakeday/commit/15533c48275b5b5d9c79e288996c203093ad4173>

编辑：我所在的时区是 UTC+5:30，但偏移量为 6 小时，因此我发现对于在 23:30 到 00:00 之间创建账户的用户存在一些边缘情况。正在调查中。

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [2020年一月16日 16:01 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/12 "2020-01-16T16:01:03Z")

</div>

> [@techAPJ](#):
>
> 我所在的时区是 UTC+5:30，但存在 6 小时的偏移，因此对于在 23:30 至 00:00 之间创建账户的用户，我遇到了一些边缘情况。正在调查中。

已通过以下方式修复：

> <https://github.com/discourse/discourse-cakeday/commit/24aa36e49ed484ae536dbf8cea2aef826786622d>

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [2020年一月16日 17:11 UTC](https://meta.discourse.org/t/anniversaries-date-off-by-one/64140/13 "2020-01-16T17:11:32Z")

</div>


