diff --git a/test/tz_test/tzdata2016c.txt.zip b/test/tz_test/tzdata2016c.txt.zip new file mode 100644 index 0000000..fcaac05 Binary files /dev/null and b/test/tz_test/tzdata2016c.txt.zip differ diff --git a/test/tz_test/validate.cpp b/test/tz_test/validate.cpp index 0299273..15a0313 100644 --- a/test/tz_test/validate.cpp +++ b/test/tz_test/validate.cpp @@ -1,6 +1,83 @@ #include "tz.h" #include +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;