chrono-Compatible Low-Level Date Algorithms

submited by
Style Pass
2024-04-18 20:00:06

The purpose of this paper is not to propose a date class. For an example date library based on these algorithms see date v2.

This paper derives and documents key algorithms that enable one to write their own date class. The purpose of this paper is to allow everyone to easily write their own date class, using algorithms that are well documented, and easily modified to meet individual needs. The algorithms presented are efficient. They require no external tables. They do not require C++11 or C++1y features, though if C++11 is available, the algorithms should be noexcept, and if C++1y is available, they can trivially be made constexpr.

This paper does not document a library. It is a how-to manual for writing the algorithm part of your own date class. The syntax and some of the language features come from C++11 and even C++1y. However the algorithms can be ported to any language.

The algorithms are interoperable with every known implementation of std::chrono::system_clock, though that interoperability depends on an unspecified property of the system_clock: its epoch. Example code will be shown how these algorithms can take advantage of the common (but unspecified) system_clock epoch.

Leave a Comment