glasslion

"YYYY-MM-dd"

  •  1
     
  •   glasslion · Dec 29, 2014 · 3956 views
    This topic created in 4179 days ago, the information mentioned may be changed or developed.
    今天有大量Twitter用户被强制登出, 并无法再次登录。
    有人抓包后发现, Twitter 的 Server 认为今天是 2015 年 12月 29日。

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

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