aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/22_locale
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-01-10 15:38:47 +0100
committerJakub Jelinek <jakub@redhat.com>2022-01-10 15:38:47 +0100
commita8d3c98746098e2784be7144c1ccc9fcc34a0888 (patch)
treeaa4b7c7d9031a5d49656f13d42d122c0c9b5f941 /libstdc++-v3/testsuite/22_locale
parent68c2e9e9234cb301e9e81792cad233a41e797792 (diff)
downloadgcc-a8d3c98746098e2784be7144c1ccc9fcc34a0888.zip
gcc-a8d3c98746098e2784be7144c1ccc9fcc34a0888.tar.gz
gcc-a8d3c98746098e2784be7144c1ccc9fcc34a0888.tar.bz2
libstdc++: Add %j, %U, %w, %W time_get support, fix %y, %Y, %C, %p [PR77760]
glibc strptime passes around some state, what fields in struct tm have been set and what needs to be finalized through possibly recursive calls, and at the end performs various finalizations, like applying %p so that it works for both %I %p and %p %I orders, or applying century so that both %C %y and %y %C works, or computation of missing fields from others (e.g. from %Y and %j one can compute tm_mon, tm_mday and tm_wday, from %Y %U %w, %Y %W %w, %Y %U %a, or %Y %W %w one can compute tm_mon, tm_mday, tm_yday or e.g. from %Y %m %d one can compute tm_wday and tm_yday. As the finalization is quite large and doesn't need to be a template (doesn't depend on any iterators or char types), I've put it into libstdc++, and left some padding in the state struct, so that perhaps in the future we can track some more state without changing ABI. Unfortunately, there is an ugly problem that the standard mandates that get method calls the do_get virtual method and I don't see how we can cary on any state in between those calls (even if we did an ABI change for the facets, the methods are const, so that I think multiple threads could use the same time_get objects and we couldn't store state in there). There is a hack for that for GCC (seems to work with ICC too, doesn't work with clang++) if the do_get method isn't overriden we can pass the state around. For both do_get_year and per IRC discussions also for %y, the behavior is if 1-2 digits are parsed, the year is treated according to POSIX 2008 %y rules (0-68 is 2000-2068, 69-99 is 1969-1999), if 3-4 digits are parsed, it is treated as %Y. 2022-01-10 Jakub Jelinek <jakub@redhat.com> PR libstdc++/77760 * include/bits/locale_facets_nonio.h (__time_get_state): New struct. (time_get::_M_extract_via_format): Declare new method with __time_get_state& as an extra argument. * include/bits/locale_facets_nonio.tcc (_M_extract_via_format): Add __state argument, set various fields in it while parsing. Handle %j, %U, %w and %W, fix up handling of %y, %Y and %C, don't adjust tm_hour for %p immediately. Add a wrapper around the method without the __state argument for backwards compatibility. (_M_extract_num): Remove all __len == 4 special cases. (time_get::do_get_time, time_get::do_get_date, time_get::do_get): Zero initialize __state, pass it to _M_extract_via_format and finalize it at the end. (do_get_year): For 1-2 digit parsed years, map 0-68 to 2000-2068, 69-99 to 1969-1999. For 3-4 digit parsed years use that as year. (get): If do_get isn't overloaded from the locale_facets_nonio.tcc version, don't call do_get but call _M_extract_via_format instead to pass around state. * config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export _M_extract_via_format with extra __time_get_state and __time_get_state::_M_finalize_state. * src/c++98/locale_facets.cc (is_leap, day_of_the_week, day_of_the_year): New functions in anon namespace. (mon_yday): New var in anon namespace. (__time_get_state::_M_finalize_state): Define. * testsuite/22_locale/time_get/get/char/4.cc: New test. * testsuite/22_locale/time_get/get/wchar_t/4.cc: New test. * testsuite/22_locale/time_get/get_year/char/1.cc (test01): Parse 197 as year 197AD instead of error. * testsuite/22_locale/time_get/get_year/char/5.cc (test01): Parse 1 as year 2001 instead of error. * testsuite/22_locale/time_get/get_year/char/6.cc: New test. * testsuite/22_locale/time_get/get_year/wchar_t/1.cc (test01): Parse 197 as year 197AD instead of error. * testsuite/22_locale/time_get/get_year/wchar_t/5.cc (test01): Parse 1 as year 2001 instead of error. * testsuite/22_locale/time_get/get_year/wchar_t/6.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale')
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get/char/4.cc243
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/4.cc243
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get_year/char/1.cc4
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get_year/char/5.cc7
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get_year/char/6.cc79
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/1.cc4
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/5.cc7
-rw-r--r--libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/6.cc79
8 files changed, 656 insertions, 10 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/char/4.cc b/libstdc++-v3/testsuite/22_locale/time_get/get/char/4.cc
new file mode 100644
index 0000000..d0619f9
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get/char/4.cc
@@ -0,0 +1,243 @@
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2021-2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <locale>
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std;
+
+ locale loc_c = locale::classic();
+
+ istringstream iss;
+ iss.imbue(loc_c);
+ const time_get<char>& tget = use_facet<time_get<char>>(iss.getloc());
+ typedef istreambuf_iterator<char> iter;
+ const iter end;
+
+ tm time;
+ ios_base::iostate err = ios_base::badbit;
+
+ iss.str("PM01:38:12");
+ string format = "%p%I:%M:%S";
+ time = tm();
+ auto ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_hour == 13 );
+ VERIFY( time.tm_min == 38 );
+ VERIFY( time.tm_sec == 12 );
+
+ iss.str("05 37");
+ format = "%C %y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 537 - 1900 );
+
+ iss.str("68");
+ format = "%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2068 - 1900 );
+
+ iss.str("69");
+ format = "%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 1969 - 1900 );
+
+ iss.str("03-Feb-2003");
+ format = "%d-%b-%Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2003 - 1900 );
+ VERIFY( time.tm_mon == 1 );
+ VERIFY( time.tm_mday == 3 );
+ VERIFY( time.tm_wday == 1 );
+ VERIFY( time.tm_yday == 33 );
+
+ iss.str("16-Dec-2020");
+ format = "%d-%b-%Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 11 );
+ VERIFY( time.tm_mday == 16 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 350 );
+
+ iss.str("16-Dec-2021");
+ format = "%d-%b-%Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2021 - 1900 );
+ VERIFY( time.tm_mon == 11 );
+ VERIFY( time.tm_mday == 16 );
+ VERIFY( time.tm_wday == 4 );
+ VERIFY( time.tm_yday == 349 );
+
+ iss.str("253 2020");
+ format = "%j %Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 8 );
+ VERIFY( time.tm_mday == 9 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 252 );
+
+ iss.str("233 2021");
+ format = "%j %Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2021 - 1900 );
+ VERIFY( time.tm_mon == 7 );
+ VERIFY( time.tm_mday == 21 );
+ VERIFY( time.tm_wday == 6 );
+ VERIFY( time.tm_yday == 232 );
+
+ iss.str("2020 23 3");
+ format = "%Y %U %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 10 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 161 );
+
+ iss.str("2020 23 3");
+ format = "%Y %W %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 10 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 161 );
+
+ iss.str("2021 43 Fri");
+ format = "%Y %W %a";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2021 - 1900 );
+ VERIFY( time.tm_mon == 9 );
+ VERIFY( time.tm_mday == 29 );
+ VERIFY( time.tm_wday == 5 );
+ VERIFY( time.tm_yday == 301 );
+
+ iss.str("2024 23 3");
+ format = "%Y %U %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2024 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 12 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 163 );
+
+ iss.str("2024 23 3");
+ format = "%Y %W %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2024 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 5 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 156 );
+
+ // As an extension, parse also 4 digit years.
+ iss.str("0068");
+ format = "%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 68 - 1900 );
+
+ iss.str("0069");
+ format = "%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 69 - 1900 );
+
+ iss.str("1492");
+ format = "%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 1492 - 1900 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/4.cc b/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/4.cc
new file mode 100644
index 0000000..0518842
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/4.cc
@@ -0,0 +1,243 @@
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2021-2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <locale>
+#include <sstream>
+#include <iterator>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std;
+
+ locale loc_c = locale::classic();
+
+ wistringstream iss;
+ iss.imbue(loc_c);
+ const time_get<wchar_t>& tget = use_facet<time_get<wchar_t>>(iss.getloc());
+ typedef istreambuf_iterator<wchar_t> iter;
+ const iter end;
+
+ tm time;
+ ios_base::iostate err = ios_base::badbit;
+
+ iss.str(L"PM01:38:12");
+ wstring format = L"%p%I:%M:%S";
+ time = tm();
+ auto ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_hour == 13 );
+ VERIFY( time.tm_min == 38 );
+ VERIFY( time.tm_sec == 12 );
+
+ iss.str(L"05 37");
+ format = L"%C %y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 537 - 1900 );
+
+ iss.str(L"68");
+ format = L"%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2068 - 1900 );
+
+ iss.str(L"69");
+ format = L"%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 1969 - 1900 );
+
+ iss.str(L"03-Feb-2003");
+ format = L"%d-%b-%Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2003 - 1900 );
+ VERIFY( time.tm_mon == 1 );
+ VERIFY( time.tm_mday == 3 );
+ VERIFY( time.tm_wday == 1 );
+ VERIFY( time.tm_yday == 33 );
+
+ iss.str(L"16-Dec-2020");
+ format = L"%d-%b-%Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 11 );
+ VERIFY( time.tm_mday == 16 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 350 );
+
+ iss.str(L"16-Dec-2021");
+ format = L"%d-%b-%Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2021 - 1900 );
+ VERIFY( time.tm_mon == 11 );
+ VERIFY( time.tm_mday == 16 );
+ VERIFY( time.tm_wday == 4 );
+ VERIFY( time.tm_yday == 349 );
+
+ iss.str(L"253 2020");
+ format = L"%j %Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 8 );
+ VERIFY( time.tm_mday == 9 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 252 );
+
+ iss.str(L"233 2021");
+ format = L"%j %Y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2021 - 1900 );
+ VERIFY( time.tm_mon == 7 );
+ VERIFY( time.tm_mday == 21 );
+ VERIFY( time.tm_wday == 6 );
+ VERIFY( time.tm_yday == 232 );
+
+ iss.str(L"2020 23 3");
+ format = L"%Y %U %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 10 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 161 );
+
+ iss.str(L"2020 23 3");
+ format = L"%Y %W %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2020 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 10 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 161 );
+
+ iss.str(L"2021 43 Fri");
+ format = L"%Y %W %a";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2021 - 1900 );
+ VERIFY( time.tm_mon == 9 );
+ VERIFY( time.tm_mday == 29 );
+ VERIFY( time.tm_wday == 5 );
+ VERIFY( time.tm_yday == 301 );
+
+ iss.str(L"2024 23 3");
+ format = L"%Y %U %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2024 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 12 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 163 );
+
+ iss.str(L"2024 23 3");
+ format = L"%Y %W %w";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 2024 - 1900 );
+ VERIFY( time.tm_mon == 5 );
+ VERIFY( time.tm_mday == 5 );
+ VERIFY( time.tm_wday == 3 );
+ VERIFY( time.tm_yday == 156 );
+
+ // As an extension, parse also 4 digit years.
+ iss.str(L"0068");
+ format = L"%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 68 - 1900 );
+
+ iss.str(L"0069");
+ format = L"%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 69 - 1900 );
+
+ iss.str(L"1492");
+ format = L"%y";
+ time = tm();
+ ret = tget.get(iter(iss), end, iss, err, &time,
+ format.data(), format.data()+format.size());
+ VERIFY( err == ios_base::eofbit );
+ VERIFY( ret == end );
+ VERIFY( time.tm_year == 1492 - 1900 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/1.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/1.cc
index c9d9896..e6f53de 100644
--- a/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/1.cc
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/1.cc
@@ -76,8 +76,8 @@ void test01()
errorstate = good;
iterator_type ret03 = tim_get.get_year(is_it03, end, iss, errorstate,
&time03);
- VERIFY( time03.tm_year == 3 );
- VERIFY( errorstate == ios_base::failbit );
+ VERIFY( time03.tm_year == 197 - 1900 );
+ VERIFY( errorstate == good );
VERIFY( *ret03 == 'd' );
iss.str("71d71");
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/5.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/5.cc
index d518d96..c454447 100644
--- a/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/5.cc
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/5.cc
@@ -49,12 +49,13 @@ void test01()
const string str0 = "1";
tg.get_year(str0.begin(), str0.end(), iss, err, &tm0);
- VERIFY( err == (failbit | eofbit) );
- VERIFY( tm0.tm_year == 0 );
+ VERIFY( err == eofbit );
+ VERIFY( tm0.tm_year == 2001 - 1900 );
const string str1 = "1997 ";
+ err = goodbit;
iter_type end1 = tg.get_year(str1.begin(), str1.end(), iss, err, &tm1);
- VERIFY( err == (failbit | eofbit) );
+ VERIFY( err == goodbit );
VERIFY( tm1.tm_year == time_sanity.tm_year );
VERIFY( *end1 == ' ' );
}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/6.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/6.cc
new file mode 100644
index 0000000..e50afa6
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get_year/char/6.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2001-2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 22.2.5.1.1 time_get members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ using namespace std;
+
+ typedef istreambuf_iterator<char> iterator_type;
+
+ locale loc_c = locale::classic();
+
+ iterator_type end;
+
+ istringstream iss;
+ iss.imbue(loc_c);
+ const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc());
+ ios_base::iostate errorstate = ios_base::goodbit;
+
+ iss.str("69");
+ iterator_type is_it01(iss);
+ tm time01;
+ tim_get.get_year(is_it01, end, iss, errorstate, &time01);
+ VERIFY( time01.tm_year == 1969 - 1900 );
+ VERIFY( errorstate == ios_base::eofbit );
+
+ iss.str("68 ");
+ iterator_type is_it02(iss);
+ tm time02;
+ errorstate = ios_base::goodbit;
+ iterator_type ret02 = tim_get.get_year(is_it02, end, iss, errorstate,
+ &time02);
+ VERIFY( time02.tm_year == 2068 - 1900 );
+ VERIFY( errorstate == ios_base::goodbit );
+ VERIFY( *ret02 == ' ' );
+
+ iss.str("0069");
+ iterator_type is_it03(iss);
+ tm time03;
+ errorstate = ios_base::goodbit;
+ iterator_type ret03 = tim_get.get_year(is_it03, end, iss, errorstate,
+ &time03);
+ VERIFY( time03.tm_year == 69 - 1900 );
+ VERIFY( errorstate == ios_base::eofbit );
+
+ iss.str("0068");
+ iterator_type is_it04(iss);
+ tm time04;
+ errorstate = ios_base::goodbit;
+ iterator_type ret04 = tim_get.get_year(is_it04, end, iss, errorstate,
+ &time04);
+ VERIFY( time04.tm_year == 68 - 1900 );
+ VERIFY( errorstate == ios_base::eofbit );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/1.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/1.cc
index e177120..ba95fb9 100644
--- a/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/1.cc
@@ -76,8 +76,8 @@ void test01()
errorstate = good;
iterator_type ret03 = tim_get.get_year(is_it03, end, iss, errorstate,
&time03);
- VERIFY( time03.tm_year == 3 );
- VERIFY( errorstate == ios_base::failbit );
+ VERIFY( time03.tm_year == 197 - 1900 );
+ VERIFY( errorstate == good );
VERIFY( *ret03 == L'd' );
iss.str(L"71d71");
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/5.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/5.cc
index 8ce1bda..c1ee710 100644
--- a/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/5.cc
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/5.cc
@@ -49,12 +49,13 @@ void test01()
const wstring str0 = L"1";
tg.get_year(str0.begin(), str0.end(), iss, err, &tm0);
- VERIFY( err == (failbit | eofbit) );
- VERIFY( tm0.tm_year == 0 );
+ VERIFY( err == eofbit );
+ VERIFY( tm0.tm_year == 2001 - 1900 );
const wstring str1 = L"1997 ";
+ err = goodbit;
iter_type end1 = tg.get_year(str1.begin(), str1.end(), iss, err, &tm1);
- VERIFY( err == (failbit | eofbit) );
+ VERIFY( err == goodbit );
VERIFY( tm1.tm_year == time_sanity.tm_year );
VERIFY( *end1 == L' ' );
}
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/6.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/6.cc
new file mode 100644
index 0000000..f6e32b7
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/time_get/get_year/wchar_t/6.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2001-2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 22.2.5.1.1 time_get members
+
+#include <locale>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ using namespace std;
+
+ typedef istreambuf_iterator<wchar_t> iterator_type;
+
+ locale loc_c = locale::classic();
+
+ iterator_type end;
+
+ wistringstream iss;
+ iss.imbue(loc_c);
+ const time_get<wchar_t>& tim_get = use_facet<time_get<wchar_t> >(iss.getloc());
+ ios_base::iostate errorstate = ios_base::goodbit;
+
+ iss.str(L"69");
+ iterator_type is_it01(iss);
+ tm time01;
+ tim_get.get_year(is_it01, end, iss, errorstate, &time01);
+ VERIFY( time01.tm_year == 1969 - 1900 );
+ VERIFY( errorstate == ios_base::eofbit );
+
+ iss.str(L"68 ");
+ iterator_type is_it02(iss);
+ tm time02;
+ errorstate = ios_base::goodbit;
+ iterator_type ret02 = tim_get.get_year(is_it02, end, iss, errorstate,
+ &time02);
+ VERIFY( time02.tm_year == 2068 - 1900 );
+ VERIFY( errorstate == ios_base::goodbit );
+ VERIFY( *ret02 == L' ' );
+
+ iss.str(L"0069");
+ iterator_type is_it03(iss);
+ tm time03;
+ errorstate = ios_base::goodbit;
+ iterator_type ret03 = tim_get.get_year(is_it03, end, iss, errorstate,
+ &time03);
+ VERIFY( time03.tm_year == 69 - 1900 );
+ VERIFY( errorstate == ios_base::eofbit );
+
+ iss.str(L"0068");
+ iterator_type is_it04(iss);
+ tm time04;
+ errorstate = ios_base::goodbit;
+ iterator_type ret04 = tim_get.get_year(is_it04, end, iss, errorstate,
+ &time04);
+ VERIFY( time04.tm_year == 68 - 1900 );
+ VERIFY( errorstate == ios_base::eofbit );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}