diff --git a/test/tz_test/README.md b/test/tz_test/README.md new file mode 100644 index 0000000..23e9f85 --- /dev/null +++ b/test/tz_test/README.md @@ -0,0 +1,28 @@ +To test: * Install tz.cpp by downloading the IANA timezone database +at: http://www.iana.org/time-zones You only need the data, not the +code. + +* Change the string `install` in tz.cpp to point to your downloaded +IANA database. + +* Compile validate.cpp along with tz.cpp. + +* Run the binary and direct the terminal output to a temporary file. + +* Unzip the tzdata file that has the version corresponding to the IANA +database you downloaded (e.g. tzdata2015f.txt.zip). + +* Compare the unzipped txt file with the output of your validate test +program. If they are identical, the test passes, else it fails. + +Miscellaneous: + +You can also compare one version of the tzdatabase with another using +these uncompressed text files. The text files contain for each +timezone its initial state, and each {offset, abbreviation} change +contained in the database up through the year 2035. As the database +versions change, minor updates to the set of these transitions are +typically made, typically due to changes in government policies. + +The tests in this section will run much faster with optimizations +cranked up. \ No newline at end of file diff --git a/test/tz_test/tzdata2015e.txt.zip b/test/tz_test/tzdata2015e.txt.zip new file mode 100644 index 0000000..144f7d3 Binary files /dev/null and b/test/tz_test/tzdata2015e.txt.zip differ diff --git a/test/tz_test/tzdata2015f.txt.zip b/test/tz_test/tzdata2015f.txt.zip new file mode 100644 index 0000000..a102e6c Binary files /dev/null and b/test/tz_test/tzdata2015f.txt.zip differ diff --git a/test/tz_test/validate.cpp b/test/tz_test/validate.cpp new file mode 100644 index 0000000..0299273 --- /dev/null +++ b/test/tz_test/validate.cpp @@ -0,0 +1,60 @@ +#include "tz.h" +#include + +int +main() +{ + using namespace date; + using namespace std::chrono; + auto& db = get_tzdb(); + std::vector names; + names.reserve(db.zones.size() + db.links.size()); + for (auto& zone : db.zones) + names.push_back(zone.name()); + for (auto& link : db.links) + names.push_back(link.name()); + std::sort(names.begin(), names.end()); + for (auto const& name : names) + { + std::cout << name << '\n'; + auto z = locate_zone(name); + auto begin = day_point(jan/1/year::min()) + 0s; + auto end = day_point(jan/1/2035) + 0s; + auto info = z->get_info(begin, tz::utc); + std::cout << "Initially: "; + if (info.offset >= 0s) + std::cout << '+'; + std::cout << make_time(info.offset); + if (info.save == 0min) + std::cout << " standard "; + else + std::cout << " daylight "; + std::cout << info.abbrev << '\n'; + 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); + if (info.offset == prev_offset && info.abbrev == prev_abbrev && + info.save == prev_save) + continue; + auto dp = floor(begin); + auto ymd = year_month_day(dp); + auto time = make_time(begin - dp); + std::cout << ymd << 'T' << time << "Z "; + if (info.offset >= 0s) + std::cout << '+'; + std::cout << make_time(info.offset); + if (info.save == 0min) + std::cout << " standard "; + else + std::cout << " daylight "; + std::cout << info.abbrev << '\n'; + prev_offset = info.offset; + prev_abbrev = info.abbrev; + prev_save = info.save; + } + std::cout << '\n'; + } +} \ No newline at end of file diff --git a/tz.cpp b/tz.cpp index fbcd888..6c92f14 100644 --- a/tz.cpp +++ b/tz.cpp @@ -113,7 +113,7 @@ namespace date #if _WIN32 // TODO: sensible default for all platforms. static std::string install{ "c:\\tzdata" }; #else -static std::string install{ "/Users/howardhinnant/Downloads/tzdata2015e" }; +static std::string install{ "/Users/howardhinnant/Downloads/tzdata2015f" }; #endif static const std::vector files =