Open ecorm opened 3 years ago
See https://gist.github.com/ecorm/8878c5075cf8557994983540a13557bc#file-main-cpp as an example of how difficult it currently is to parse an arbitrary ISO 8601 string into an arbitrary time_point
.
The basic design of parse is strptime
with just a few extensions which are clear omissions when compared with strftime
. For example strftime
has %F
as an equivalent to %Y-%m-%d
, and strptime
doesn't, for no apparent reason. So %F
is an example of a minor extension supported in parse
.
This design is now cemented in C++20. To get something new in parse
, it would have to be something I thought had a reasonable chance of going into a future C++ standard. This library serves as a C++ testbed for future standardization possibilities.
Well, I think a sane way of parsing ISO 8601 should be added to the C++ standard library. Other mainstream languages have an easy way to parse ISO 8601 strings. This library would be the natural place to introduce such a feature. If not parsing flags, then some kind of utility function.
I don't want to pressure you into championing an idea you don't believe in. Is this feature doesn't interest you, I'll understand and won't hold it against you. I suppose I could write up a C++ standard library proposal myself, but I don't like getting involved in politics.
If you propose something here, I'll certainly consider it.
As I've reported in #683, parsing ISO 8601 date/time strings via this library (and C++20) is problematic due to the following reasons:
Without using the
%NS
specifier with an arbitrarily large enoughN
, it does not consume all available subsecond digits. Even if suitably largeN
is provided in an explicit%NS
specifier, parsing>= 59.5
seconds intosys_seconds
fails because it assumes round-to-nearest and thinks that we're trying to parse a time of day ofHH:MM:60
.It can only parse either
Z
or anHH:SS
offset. The%Ez
specifier does not recognizeZ
as being the equivalent of a00:00
offset.It does not allow
60.x
seconds when parsing into asys_time
. This forces the library user to provide an environment with a working leap seconds database, and to parse viautc_time
before converting it to asys_time
.The current set of parsing flags are too rigid and do not allow any valid, arbitrary ISO 8601 timestamp as input. This makes it difficult for a C++ program to interoperate with ISO8601 strings produced by other languages, where the resolution and leap second support may differ.
On the formatting side, the library currently lacks a means of automatically adding the
-
prefix for dates preceding year 0, as well as the+
prefix for for dates after the year 9999 when formatting into an ISO 8601 string. The user is forced to calculate the year and manually add a leading+
/-
if necessary. The year calculation ends up being computed twice: once by the user, and again by theformat
function.ISO 8601 (as well as the closely related RFC3339) is a very common way of exchanging date/times. It should be part of the C++ standard library and be simple to parse/format without having to jump through hoops.