aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstdc++-v3/include/bits/chrono_io.h9
-rw-r--r--libstdc++-v3/testsuite/std/time/year/io.cc7
2 files changed, 12 insertions, 4 deletions
diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h
index 16e8fc5..b63b859 100644
--- a/libstdc++-v3/include/bits/chrono_io.h
+++ b/libstdc++-v3/include/bits/chrono_io.h
@@ -820,9 +820,14 @@ namespace __format
if (__conv == 'Y' || __conv == 'C')
{
- if (__is_neg)
- __s.assign(1, _S_plus_minus[1]);
int __ci = __yi / 100;
+ if (__is_neg) [[unlikely]]
+ {
+ __s.assign(1, _S_plus_minus[1]);
+ // For floored division -123//100 is -2 and -100//100 is -1
+ if ((__ci * 100) != __yi)
+ ++__ci;
+ }
if (__ci >= 100) [[unlikely]]
{
__s += std::format(_S_empty_spec, __ci / 100);
diff --git a/libstdc++-v3/testsuite/std/time/year/io.cc b/libstdc++-v3/testsuite/std/time/year/io.cc
index 6157afa..a6683ae 100644
--- a/libstdc++-v3/testsuite/std/time/year/io.cc
+++ b/libstdc++-v3/testsuite/std/time/year/io.cc
@@ -43,8 +43,11 @@ test_format()
s = std::format("{}", --year::min()); // formatted via ostream
VERIFY( s == "-32768 is not a valid year" );
- s = std::format("{:%y} {:%y}", 1976y, -1976y);
- VERIFY( s == "76 76" ); // LWG 3831
+ s = std::format("{:%C %y} {:%C %y}", 1976y, -1976y);
+ VERIFY( s == "19 76 -20 76" ); // LWG 3831
+
+ s = std::format("{:%C %y} {:%C %y} {:%C %y}", -9y, -900y, -555y);
+ VERIFY( s == "-01 09 -09 00 -06 55" ); // LWG 4022
s = std::format("{0:%EC}{0:%Ey} = {0:%EY}", 1642y);
VERIFY( s == "1642 = 1642" );