C++ 20是否需要实现IANA时区数据库的使用?

发布于 2025-01-23 11:39:59 字数 797 浏览 0 评论 0 原文

C ++ 20 < chrono> 库带有本地时间和时区支持。该库的界面与 iana时区数据库的界面 C ++标准要求该实施实际使用IANA时区数据库及其所有历史数据?

在线C ++参考声称它确实:请参阅此处。 C ++标准本身包含a 弱语句

[time.zone]描述了一个访问IANA时区数据库的接口,该界面与sys_time和local_time互动。 该界面为民用日历类型([time.cal])和用户定义的日历提供了时区支持。

它仅提及界面,但不提及数据。标准中时区库的后续描述没有进一步提及IANA时区数据库。

我的结论是, c ++参考是错误的,并且不需要使用该实施。 IANA时区数据库。有人可以确认这个结论是否正确吗?

C++20 <chrono> library comes with local time and time zone support. The interface of this library is compatible with that of IANA Time Zone Database, but the question is, does C++ Standard require that the implementation actually uses IANA Time Zone Database with all its historical data?

The online C++ reference claims that it does: see here. The C++ Standard itself contains a weaker statement:

[time.zone] describes an interface for accessing the IANA Time Zone Database that interoperates with sys_­time and local_­time.
This interface provides time zone support to both the civil calendar types ([time.cal]) and to user-defined calendars.

It only mentions the interface, but not the data. The subsequent description of the timezone library in the Standard makes no further reference to IANA Time Zone Database.

My conclusion is that C++ Reference is wrong, and the implementation is not required to use the IANA Time Zone Database. Can someone confirm if this conclusion is correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2025-01-30 11:39:59

C ++标准委员会的图书馆工作组与这些单词很多,试图使它们正确。目的是std :: lib提供 iana时区数据库。也许更重要的是,所有三个主要的std :: lib供应商都符合这种意图。

未显示在在线标准是标准的参考书目部分,其中包含:


请注意> STD :: Chrono 还支持用户写的时区。 这是一个 1 1 1 /sup>,这是其用途的一个示例:

#include "date/ptz.h"
#include <iostream>

int
main()
{
    using namespace date;
    using namespace std;
    using namespace std::chrono;

    auto now = system_clock::now();
    auto tzp = Posix::time_zone{"EST5EDT,M3.2.0,M11.1.0"};
    cout << zoned_time{tzp, now} << '\n';
}

此示例模型此示例显示了“ America/New_york”的当前定义(2007年之前没有历史数据)。


1 此示例与 pre-c ++ 20 Chrono Preview 反对 std :: Chrono 。要更改它,它只需要引用 namespace Date 可以更改为 namespace std :: Chrono

The Library Working Group of the C++ Standards Committee wrestled with those words for quite a bit, trying to get them right. The intent is that the std::lib supplies the IANA Time Zone Database. And perhaps even more importantly, all three major std::lib vendors are on-board with that intent.

Not shown in the online standard is a bibliography section of the standard which contains:


Note that std::chrono also supports user-written timezones as well. Here is an example of one1, and here is an example of its use:

#include "date/ptz.h"
#include <iostream>

int
main()
{
    using namespace date;
    using namespace std;
    using namespace std::chrono;

    auto now = system_clock::now();
    auto tzp = Posix::time_zone{"EST5EDT,M3.2.0,M11.1.0"};
    cout << zoned_time{tzp, now} << '\n';
}

This example models POSIX timezones and this example shows the current definition of "America/New_York" (without historical data preceding 2007).


1This example is coupled to the pre-C++20 chrono preview as opposed to std::chrono. To change it would only require references to namespace date be changed to namespace std::chrono.

望笑 2025-01-30 11:39:59

我的阅读是,该语言要求实现能够使用IANA时区数据库或模仿它的任何内容。这意味着需要一个区域具有名称,UTC的三角洲,并且可以(可选地)定义节日省的时间,每年更改时间。

但是该数据库的实际内容超出了C ++标准,并且属于操作系统。这意味着,如果操作系统提供IANA时区数据库的真实(和最新),则该程序将可以访问它,但是该标准并不要求OS具有最新的副本,而不是实现在操作系统中携带一个。

My reading is that the language requires the implementation to be able to use the IANA Time Zone Database or anything mimicing it. That means that a zone is required to have a name, a delta from UTC, and optionally the definition of a Daylight Saving Time with times of change per year.

But the actual content of that database is beyond the C++ standard and belongs to the Operating System. That means that if the OS provides a true (and up to date) copy of the IANA Time Zone Database, the program will have access to it, but the standard does not mandate the OS to have that up to date copy, not the implementation to carry one in the OS does not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文