V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
glasslion
V2EX  ›  分享发现

"YYYY-MM-dd"

  •  1
     
  •   glasslion · 2014-12-29 16:39:57 +08:00 · 3280 次点击
    这是一个创建于 3412 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今天有大量Twitter用户被强制登出, 并无法再次登录。
    有人抓包后发现, Twitter 的 Server 认为今天是 2015 年 12月 29日。

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

    很有可能是因为某个无证程序员没搞明 Year yyyy)和 Week year(YYYY) 的区别, 一年里的绝大部分日子也无法重现这个bug, 于是乎就悲剧了。
    11 条回复    2014-12-30 13:19:40 +08:00
    txx
        1
    txx  
       2014-12-29 17:01:17 +08:00
    我还以为我被认证了...
    Jelen
        2
    Jelen  
       2014-12-29 17:11:21 +08:00
    区别是什么,我还是不理解
    glasslion
        3
    glasslion  
    OP
       2014-12-29 17:14:52 +08:00
    @Jelen
    $ date '+%G-%m-%d'
    2015-12-29
    clino
        4
    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
        5
    typcn  
       2014-12-29 17:30:51 +08:00
    不太懂
    typcn
        6
    typcn  
       2014-12-29 17:31:01 +08:00
    new Date().toISOString()
    "2014-12-29T09:30:41.784Z"
    msg7086
        7
    msg7086  
       2014-12-29 17:31:28 +08:00 via iPhone
    日期导致的错误其实挺常见的。
    我以前做过的一个系统,只有在12月才会出错,连测试代码都没抓出来的错。到12月才会测试失败。
    glasslion
        8
    glasslion  
    OP
       2014-12-29 17:31:59 +08:00
    @clino 嗯,说到底, 还是 Java 的 这个API 设计的有问题。
    python 里的 `isocalendar()`, shell里 的 `%G和%Y` 都不容易导致误用。 而 `YYYY` 和 `yyyy` 就容易混淆多了。
    Jelen
        9
    Jelen  
       2014-12-29 17:40:14 +08:00
    @glasslion 说到底,其实是调用函数错误了
    simonlei
        10
    simonlei  
       2014-12-29 17:59:04 +08:00   ❤️ 2
    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
        11
    vjnjc  
       2014-12-30 13:19:40 +08:00
    悲剧了,我也写了很多YYYY的代码...[sad
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2153 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:43 · PVG 19:43 · LAX 04:43 · JFK 07:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.