public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Add test for chrono::utc_clock leap second offset
@ 2022-11-16 15:07 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2022-11-16 15:07 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk.

-- >8 --

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.
---
 .../testsuite/std/time/clock/utc/1.cc         | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/libstdc++-v3/testsuite/std/time/clock/utc/1.cc b/libstdc++-v3/testsuite/std/time/clock/utc/1.cc
index eef5f3c3a48..18578fb1ab1 100644
--- a/libstdc++-v3/testsuite/std/time/clock/utc/1.cc
+++ b/libstdc++-v3/testsuite/std/time/clock/utc/1.cc
@@ -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();
 }
-- 
2.38.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-16 15:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 15:07 [committed] libstdc++: Add test for chrono::utc_clock leap second offset Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).