mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-26 07:53:16 +08:00
Update tz validation test with more checking
This commit is contained in:
parent
70f7d52f88
commit
d8426940d7
BIN
test/tz_test/tzdata2016c.txt.zip
Normal file
BIN
test/tz_test/tzdata2016c.txt.zip
Normal file
Binary file not shown.
@ -1,6 +1,83 @@
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
|
||||
void
|
||||
test_info(const date::Zone* zone, const date::Info& info)
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
auto begin = info.begin;
|
||||
auto end = info.end - microseconds{1};
|
||||
auto mid = begin + (end - begin) /2 ;
|
||||
|
||||
if (begin > day_point{jan/1/1700})
|
||||
{
|
||||
auto local = zone->to_local(begin).first;
|
||||
auto prev_local = zone->to_local(begin - seconds{1}).first;
|
||||
if (prev_local < local - seconds{1})
|
||||
{
|
||||
assert(zone->to_sys(local) == begin);
|
||||
auto imaginary = prev_local + (local - seconds{1} - prev_local) / 2;
|
||||
try
|
||||
{
|
||||
zone->to_sys(imaginary);
|
||||
assert(false);
|
||||
}
|
||||
catch (const nonexistent_local_time&)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (prev_local > local - seconds{1})
|
||||
{
|
||||
auto ambiguous = local - seconds{1} +
|
||||
(prev_local - (local - seconds{1})) / 2;
|
||||
try
|
||||
{
|
||||
zone->to_sys(ambiguous);
|
||||
assert(false);
|
||||
}
|
||||
catch (const ambiguous_local_time&)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto local = zone->to_local(mid).first;
|
||||
assert(zone->to_sys(local) == mid);
|
||||
|
||||
if (end < day_point{jan/1/3000})
|
||||
{
|
||||
auto local = zone->to_local(end).first;
|
||||
auto next_local = zone->to_local(info.end).first;
|
||||
if (next_local < local + microseconds{1})
|
||||
{
|
||||
auto ambiguous = next_local + (local + microseconds{1} - next_local) / 2;
|
||||
try
|
||||
{
|
||||
zone->to_sys(ambiguous);
|
||||
assert(false);
|
||||
}
|
||||
catch (const ambiguous_local_time&)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (next_local > local + microseconds{1})
|
||||
{
|
||||
assert(zone->to_sys(local) == end);
|
||||
auto imaginary = local + microseconds{1} +
|
||||
(next_local - (local + microseconds{1})) / 2;
|
||||
try
|
||||
{
|
||||
zone->to_sys(imaginary);
|
||||
assert(false);
|
||||
}
|
||||
catch (const nonexistent_local_time&)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -14,6 +91,7 @@ main()
|
||||
for (auto& link : db.links)
|
||||
names.push_back(link.name());
|
||||
std::sort(names.begin(), names.end());
|
||||
std::cout << db.version << "\n\n";
|
||||
for (auto const& name : names)
|
||||
{
|
||||
std::cout << name << '\n';
|
||||
@ -30,12 +108,14 @@ main()
|
||||
else
|
||||
std::cout << " daylight ";
|
||||
std::cout << info.abbrev << '\n';
|
||||
test_info(z, info);
|
||||
auto prev_offset = info.offset;
|
||||
auto prev_abbrev = info.abbrev;
|
||||
auto prev_save = info.save;
|
||||
for (begin = info.end; begin < end; begin = info.end)
|
||||
{
|
||||
info = z->get_info(begin, tz::utc);
|
||||
test_info(z, info);
|
||||
if (info.offset == prev_offset && info.abbrev == prev_abbrev &&
|
||||
info.save == prev_save)
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user