[committed] libstdc++: Add test for chrono::utc_clock leap second offset
Commit Message
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(+)
@@ -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();
}