Strftime's %C and %y formats versus wide-ranging tm_year values

Olson, Arthur David (NIH/NCI) olsona at dc37a.nci.nih.gov
Wed Sep 22 13:02:41 UTC 2004


The current standard calls for strftime to produce these results:
	%C: Replaced by the year divided by 100 and truncated to an integer,
	as a decimal number [00,99].

	%y: Replaced by the last two digits of the year
	as a decimal number [00,99].
The standard is fine where time_t values are 32 bits and the tm_year values
associated with these time_t values are always positive, four-digit
integers.
We're now trying to cope with systems using 64-bit time_t values; the
associated time_t values are much wider ranging.

Below is a table with suggested %C and %y outputs for wide-ranging years.
Note that:
	1. %y is always in the range [00,99].
	2. %C is in the range [00,99] whenever possible.
	3. %C is two characters long whenever possible.
	4. Using the format "%C%y" produces the year in all cases (with
leading zeroes in some cases).

Is there a better solution?

				--ado

tm_year         %C      %y
...
10001           100     01
10000           100     00
9999            99      99
...
1001            10      01
1000            10      00
999             09      99
...
101             01      01
100             01      00
99              00      99
...
11              00      11
10              00      10
9               00      09
...
1               00      01
0               00      00
-1              -0      01
...
-9              -0      09
-10             -0      10
-11             -0      11
...
-99             -0      99
-100            -1      00
-101            -1      01
...
-999            -9      99
-1000           -10     00
-1001           -10     01
...
-9999           -99     99
-10000          -100    00
-10001          -100    01
...



More information about the tz mailing list