C++ Logo

std-discussion

Advanced search

Years before std::chrono::year{1}

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Tue, 8 Aug 2023 20:15:36 +0800
When playing with the GCC support of chrono, I notice that the year
before 1y is 0y, not -1y (my first intuition about 1 BC). Checking the
Standard, it seems the behaviour is correct, as the Standard does not
say anything should special be done in operator--. It also makes the
calendar arithmetic simpler. I then also notice that this is the way
described in ISO 8601:2004. However, although ISO 8601 is referred to
in the Standard, the parts about the calendar do not mention ISO 8601.
We just have "year represents a year in the civil calendar" in
[time.cal.year.overview], without any mention of ISO 8601, or how 0
and negative years are interpreted.

Should it be explicitly clarified that the year and related data
structures conform to ISO 8601, and 0y represents 1 BC, etc.?

A related issue is in [time.format]. The description of "%Y" only says
"The year as a decimal number" (while "%z" does mention ISO 8601). It
goes on to say "If the result is less than four digits it is
left-padded with 0 to four digits." And I find out that GCC outputs
-1y as "-001" (three digits). I am not sure whether that should be
counted as a bug.... If it is, it proves that an explicit mention of
negative years would be helpful.

Best regards,

Yongwei

-- 
Yongwei Wu
URL: http://wyw.dcweb.cn/

Received on 2023-08-08 12:15:50