Home > Mobile >  Does C 20 require of the implementations the use of IANA Time Zone Database?
Does C 20 require of the implementations the use of IANA Time Zone Database?

Time:04-25

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?

CodePudding user response:

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.

CodePudding user response:

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.

  • Related