这个“ISOTIME”结构代表什么标准?

时间:2009-05-21 16:57:17

标签: c++ datetime data-structures timezone

在我们的代码中,我们有一个16字节的打包struct,我们称之为“ISOTIME”:

typedef struct isotime {
    struct {
        uint16_t iso_zone : 12; // corresponding time zone
        uint16_t iso_type : 4; // type of iso date
    } iso_fmt;

    int16_t iso_year; // year
    uint8_t iso_month; // month
    uint8_t iso_day; // day
    uint8_t iso_hour; // hour
    uint8_t iso_minute; // minute
    uint8_t iso_second; // second
    uint8_t iso_centi; // centi-second
    uint8_t iso_hundred; // hundreds of micro-seconds
    uint8_t iso_micro; // micro-seconds
    uint32_t iso_unused; // pad out to 16 bytes
} ISOTIME; 

我正在试图找出应该实施的标准。有人有线索吗?我的Google-fu让我失望。

3 个答案:

答案 0 :(得分:2)

正如Gary Ray所说,日期和时间数据交换的主要标准是ISO 8601:2004。

显示的数据结构可以处理标准格里高利历,时间分辨率为微秒。

还有其他相关标准 - 例如ISO / IEC 9899:1999(C)。它定义了一个不同的结构并指定了年份的编码(例如,年份编号 - 1900存储在tm_year元素中;也就是说,月份数字从1月份的0到11月份的11月份 - 很适合索引到月份名称数组但是否则糟糕)。 POSIX(ISO / IEC 9945-1:2008)继承了C标准的时间处理。 SQL(ISO / IEC 9075-2:2008)与ISO 8601的结合比与C / POSIX的结合更为密切。但是显示的结构可以在任何这些环境中使用 - 尽管它在C / POSIX环境中不是标准的。

答案 1 :(得分:2)

国际标准很少关注数据的详细内存表示,特别是在位级别(浮点标准当然例外)。这是因为这些东西本质上是不可移植的。这并不是说这种结构没有标准,但我认为这不太可能。

答案 2 :(得分:1)

看起来像是一个处理ISO 8601的结构 - 格式取决于数据的显示方式:

20030103 = Basic Format
20030103T0700-0500 = Basic Format w/ Time and Zone
2003-01-03 = Extended Format