代码之家  ›  专栏  ›  技术社区  ›  novelistparty

如何获得日期(1)/时间(3)可表示/接受的日期范围?

  •  0
  • novelistparty  · 技术社区  · 8 年前

    date -ju -f "%F" "1901-12-14" "+%s"

    我查了macOS的来源 date here (Apple Open Source) 这是一个失败的 mktime 给你的电话 date: nonexistent time 较早日期的错误。

    mktime公司 here (Apple Open Source)

    如何找到或计算 日期 mktime公司

    如果我想得到一个不能用 内部,还有什么其他库或函数可以处理较早的日期?

    1 回复  |  直到 8 年前
        1
  •  1
  •   kdhp    8 年前

    当前macOS(OS X)的实现 mktime(3) 至少支持Unix时间为 INT32_MIN ( -2147483648 localtime.c:2102 INT32_MAX :

    /* optimization: see if the value is 31-bit (signed) */
    t = (((time_t) 1) << (TYPE_BIT(int) - 1)) - 1;
    bits = ((*funcp)(&t, offset, &mytm) == NULL || tmcomp(&mytm, &yourtm) < 0) ? TYPE_BIT(time_t) - 1 : TYPE_BIT(int) - 1;
    

    1901-12-14 1901-12-13 Unix时间下降如下 INT32_最小值 ,需要大于32位,但仍小于 导致功能耗尽 bits .

    考虑到1900年之前的值被 localtime.c:2073

    /* Don't go below 1900 for POLA */
    if (yourtm.tm_year < 0)
            return WRONG;
    

    (POLA:最小惊讶原则)

    此外, time_t required to be signed .

    推荐文章