]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add test for chrono::utc_clock leap second offset
authorJonathan Wakely <jwakely@redhat.com>
Wed, 16 Nov 2022 15:04:32 +0000 (15:04 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 16 Nov 2022 15:07:17 +0000 (15:07 +0000)
This test of leap second handling is taken from the C++20 standard.

libstdc++-v3/ChangeLog:

* testsuite/std/time/clock/utc/1.cc: Check handling across leap
second insertion.

libstdc++-v3/testsuite/std/time/clock/utc/1.cc

index eef5f3c3a48582f078520cee555195ea21a628c8..18578fb1ab10a1e8658832c9f278a722a096c5f5 100644 (file)
@@ -9,6 +9,8 @@ test01()
 {
   using namespace std::chrono;
 
+  // [time.clock.utc.overview]
+
   auto epoch = sys_seconds{sys_days{1970y/January/1}};
   auto utc_epoch = clock_cast<utc_clock>(epoch);
   VERIFY( utc_epoch.time_since_epoch() == 0s );
@@ -18,7 +20,29 @@ test01()
   VERIFY( utc_y2k.time_since_epoch() == 946'684'822s );
 }
 
+void
+test02()
+{
+  using namespace std::chrono;
+
+  // [time.clock.utc.members]
+
+  auto t = sys_days{July/1/2015} - 2ns;
+  auto u = utc_clock::from_sys(t);
+  VERIFY(u.time_since_epoch() - t.time_since_epoch() == 25s);
+  t += 1ns;
+  u = utc_clock::from_sys(t);
+  VERIFY(u.time_since_epoch() - t.time_since_epoch() == 25s);
+  t += 1ns;
+  u = utc_clock::from_sys(t);
+  VERIFY(u.time_since_epoch() - t.time_since_epoch() == 26s);
+  t += 1ns;
+  u = utc_clock::from_sys(t);
+  VERIFY(u.time_since_epoch() - t.time_since_epoch() == 26s);
+}
+
 int main()
 {
   test01();
+  test02();
 }