From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Add test for chrono::utc_clock leap second offset
Date: Wed, 16 Nov 2022 15:07:35 +0000 [thread overview]
Message-ID: <20221116150735.1374787-1-jwakely@redhat.com> (raw)
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
reply other threads:[~2022-11-16 15:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221116150735.1374787-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).