| 1 |
// { dg-do run { target c++20 } } |
| 2 |
// { dg-require-effective-target tzdb } |
| 3 |
// { dg-require-effective-target cxx11_abi } |
| 4 |
// { dg-xfail-run-if "no weak override on AIX" { powerpc-ibm-aix* } } |
| 5 |
|
| 6 |
#include <chrono> |
| 7 |
#include <fstream> |
| 8 |
#include <testsuite_hooks.h> |
| 9 |
|
| 10 |
static bool override_used = false; |
| 11 |
|
| 12 |
namespace __gnu_cxx |
| 13 |
{ |
| 14 |
const char* zoneinfo_dir_override() { |
| 15 |
override_used = true; |
| 16 |
return "./"; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
void |
| 21 |
test_load_leapseconds() |
| 22 |
{ |
| 23 |
std::ofstream("leapseconds") << R"( |
| 24 |
# These are all the real leap seconds as of 2024: |
| 25 |
Leap 1972 Jun 30 23:59:60 + S |
| 26 |
Leap 1972 Dec 31 23:59:60 + S |
| 27 |
Leap 1973 Dec 31 23:59:60 + S |
| 28 |
Leap 1974 Dec 31 23:59:60 + S |
| 29 |
Leap 1975 Dec 31 23:59:60 + S |
| 30 |
Leap 1976 Dec 31 23:59:60 + S |
| 31 |
Leap 1977 Dec 31 23:59:60 + S |
| 32 |
Leap 1978 Dec 31 23:59:60 + S |
| 33 |
Leap 1979 Dec 31 23:59:60 + S |
| 34 |
Leap 1981 Jun 30 23:59:60 + S |
| 35 |
Leap 1982 Jun 30 23:59:60 + S |
| 36 |
Leap 1983 Jun 30 23:59:60 + S |
| 37 |
Leap 1985 Jun 30 23:59:60 + S |
| 38 |
Leap 1987 Dec 31 23:59:60 + S |
| 39 |
Leap 1989 Dec 31 23:59:60 + S |
| 40 |
Leap 1990 Dec 31 23:59:60 + S |
| 41 |
Leap 1992 Jun 30 23:59:60 + S |
| 42 |
Leap 1993 Jun 30 23:59:60 + S |
| 43 |
Leap 1994 Jun 30 23:59:60 + S |
| 44 |
Leap 1995 Dec 31 23:59:60 + S |
| 45 |
Leap 1997 Jun 30 23:59:60 + S |
| 46 |
Leap 1998 Dec 31 23:59:60 + S |
| 47 |
Leap 2005 Dec 31 23:59:60 + S |
| 48 |
Leap 2008 Dec 31 23:59:60 + S |
| 49 |
Leap 2012 Jun 30 23:59:60 + S |
| 50 |
Leap 2015 Jun 30 23:59:60 + S |
| 51 |
Leap 2016 Dec 31 23:59:60 + S |
| 52 |
# These are fake leap seconds for testing purposes: |
| 53 |
Leap 2093 Jun 30 23:59:59 - S |
| 54 |
Leap 2093 Dec 31 23:59:60 + S |
| 55 |
)"; |
| 56 |
|
| 57 |
const auto& db = std::chrono::get_tzdb(); |
| 58 |
VERIFY( override_used ); // If this fails then XFAIL for the target. |
| 59 |
|
| 60 |
using namespace std::chrono; |
| 61 |
// XXX update this value if the number of hardcoded leap seconds changes: |
| 62 |
VERIFY( db.leap_seconds.size() == 29 ); |
| 63 |
|
| 64 |
auto i = db.leap_seconds.end() - 2; |
| 65 |
|
| 66 |
VERIFY( i[0].date() == sys_days(2093y/July/1) - 1s ); |
| 67 |
VERIFY( i[0].value() == -1s ); |
| 68 |
|
| 69 |
VERIFY( i[1].date() == sys_days(2094y/January/1) ); |
| 70 |
VERIFY( i[1].value() == 1s ); |
| 71 |
} |
| 72 |
|
| 73 |
int main() |
| 74 |
{ |
| 75 |
test_load_leapseconds(); |
| 76 |
} |