forked from HowardHinnant/date
Add validate test for timezones
This commit is contained in:
28
test/tz_test/README.md
Normal file
28
test/tz_test/README.md
Normal file
@@ -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.
|
BIN
test/tz_test/tzdata2015e.txt.zip
Normal file
BIN
test/tz_test/tzdata2015e.txt.zip
Normal file
Binary file not shown.
BIN
test/tz_test/tzdata2015f.txt.zip
Normal file
BIN
test/tz_test/tzdata2015f.txt.zip
Normal file
Binary file not shown.
60
test/tz_test/validate.cpp
Normal file
60
test/tz_test/validate.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "tz.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
using namespace date;
|
||||||
|
using namespace std::chrono;
|
||||||
|
auto& db = get_tzdb();
|
||||||
|
std::vector<std::string> 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<days>(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';
|
||||||
|
}
|
||||||
|
}
|
2
tz.cpp
2
tz.cpp
@@ -113,7 +113,7 @@ namespace date
|
|||||||
#if _WIN32 // TODO: sensible default for all platforms.
|
#if _WIN32 // TODO: sensible default for all platforms.
|
||||||
static std::string install{ "c:\\tzdata" };
|
static std::string install{ "c:\\tzdata" };
|
||||||
#else
|
#else
|
||||||
static std::string install{ "/Users/howardhinnant/Downloads/tzdata2015e" };
|
static std::string install{ "/Users/howardhinnant/Downloads/tzdata2015f" };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const std::vector<std::string> files =
|
static const std::vector<std::string> files =
|
||||||
|
Reference in New Issue
Block a user