"YYYY-MM-dd"

2014-12-29 16:39:57 +08:00
 glasslion
今天有大量Twitter用户被强制登出, 并无法再次登录。
有人抓包后发现, Twitter 的 Server 认为今天是 2015 年 12月 29日。

https://twitter.com/_Ninji/status/549365454322802688

很有可能是因为某个无证程序员没搞明 Year yyyy)和 Week year(YYYY) 的区别, 一年里的绝大部分日子也无法重现这个bug, 于是乎就悲剧了。
3313 次点击
所在节点    分享发现
11 条回复
txx
2014-12-29 17:01:17 +08:00
我还以为我被认证了...
Jelen
2014-12-29 17:11:21 +08:00
区别是什么,我还是不理解
glasslion
2014-12-29 17:14:52 +08:00
@Jelen
$ date '+%G-%m-%d'
2015-12-29
clino
2014-12-29 17:23:13 +08:00
```
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> print datetime.date.today()
2014-12-29
>>> print datetime.date.today().isocalendar()
(2015, 1, 1)
```
typcn
2014-12-29 17:30:51 +08:00
不太懂
typcn
2014-12-29 17:31:01 +08:00
new Date().toISOString()
"2014-12-29T09:30:41.784Z"
msg7086
2014-12-29 17:31:28 +08:00
日期导致的错误其实挺常见的。
我以前做过的一个系统,只有在12月才会出错,连测试代码都没抓出来的错。到12月才会测试失败。
glasslion
2014-12-29 17:31:59 +08:00
@clino 嗯,说到底, 还是 Java 的 这个API 设计的有问题。
python 里的 `isocalendar()`, shell里 的 `%G和%Y` 都不容易导致误用。 而 `YYYY` 和 `yyyy` 就容易混淆多了。
Jelen
2014-12-29 17:40:14 +08:00
@glasslion 说到底,其实是调用函数错误了
simonlei
2014-12-29 17:59:04 +08:00
A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values.

For example, January 1, 1998 is a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (ISO 8601 standard compatible setting), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. The week year is 1998 for the last three days of calendar year 1997. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997 and their week year is 1997.

就是说,今天这个星期的week year是2015...
vjnjc
2014-12-30 13:19:40 +08:00
悲剧了,我也写了很多YYYY的代码...[sad

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/157624

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX