2017-10-24 12:06:50 -04:00
|
|
|
#include "date/tz.h"
|
2015-08-15 16:00:42 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
2016-04-17 21:51:30 -04:00
|
|
|
void
|
2016-05-31 10:10:33 -04:00
|
|
|
test_info(const date::time_zone* zone, const date::sys_info& info)
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
|
|
|
using namespace date;
|
|
|
|
using namespace std::chrono;
|
|
|
|
auto begin = info.begin;
|
|
|
|
auto end = info.end - microseconds{1};
|
2016-04-21 16:08:06 -04:00
|
|
|
auto mid = begin + (end - begin) /2;
|
2024-05-08 17:15:38 +02:00
|
|
|
using sys_microseconds = date::sys_time<microseconds>;
|
2016-04-21 16:08:06 -04:00
|
|
|
using zoned_microseconds = zoned_time<microseconds>;
|
|
|
|
zoned_microseconds local{zone};
|
2016-04-17 21:51:30 -04:00
|
|
|
|
2016-04-21 16:08:06 -04:00
|
|
|
if (begin > sys_days{jan/1/1700})
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
auto prev_local = local;
|
|
|
|
local = begin;
|
|
|
|
prev_local = begin - seconds{1};
|
|
|
|
auto slocal = local.get_local_time();
|
|
|
|
auto plocal = prev_local.get_local_time();
|
|
|
|
if (plocal < slocal - seconds{1})
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
assert(sys_microseconds{local} == begin);
|
2016-04-17 21:51:30 -04:00
|
|
|
try
|
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
local = plocal + (slocal - seconds{1} - plocal) / 2;
|
2016-04-17 21:51:30 -04:00
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (const nonexistent_local_time&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2016-04-21 16:08:06 -04:00
|
|
|
else if (plocal > slocal - seconds{1})
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
local = slocal - seconds{1} + (plocal - (slocal - seconds{1})) / 2;
|
2016-04-17 21:51:30 -04:00
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (const ambiguous_local_time&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 16:08:06 -04:00
|
|
|
local = mid;
|
|
|
|
assert(sys_microseconds{local} == mid);
|
2016-04-17 21:51:30 -04:00
|
|
|
|
2016-04-21 16:08:06 -04:00
|
|
|
if (end < sys_days{jan/1/3000})
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
local = end;
|
|
|
|
auto next_local = local;
|
|
|
|
next_local = info.end;
|
|
|
|
auto slocal = local.get_local_time();
|
|
|
|
auto nlocal = next_local.get_local_time();
|
|
|
|
if (nlocal < slocal + microseconds{1})
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
local = nlocal + (slocal + microseconds{1} - nlocal) / 2;
|
2016-04-17 21:51:30 -04:00
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (const ambiguous_local_time&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2016-04-21 16:08:06 -04:00
|
|
|
else if (nlocal > slocal + microseconds{1})
|
2016-04-17 21:51:30 -04:00
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
assert(sys_microseconds{local} == end);
|
2016-04-17 21:51:30 -04:00
|
|
|
try
|
|
|
|
{
|
2016-04-21 16:08:06 -04:00
|
|
|
local = slocal + microseconds{1} +
|
|
|
|
(nlocal - (slocal + microseconds{1})) / 2;
|
2016-04-17 21:51:30 -04:00
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
catch (const nonexistent_local_time&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 00:52:32 +12:00
|
|
|
void
|
|
|
|
tzmain()
|
2015-08-15 16:00:42 -04:00
|
|
|
{
|
|
|
|
using namespace date;
|
|
|
|
using namespace std::chrono;
|
|
|
|
auto& db = get_tzdb();
|
|
|
|
std::vector<std::string> names;
|
2017-06-04 14:58:57 -04:00
|
|
|
#if USE_OS_TZDB
|
|
|
|
names.reserve(db.zones.size());
|
|
|
|
for (auto& zone : db.zones)
|
|
|
|
names.push_back(zone.name());
|
|
|
|
#else // !USE_OS_TZDB
|
2015-08-15 16:00:42 -04:00
|
|
|
names.reserve(db.zones.size() + db.links.size());
|
2016-08-05 20:16:09 -04:00
|
|
|
for (auto& zone : db.zones)
|
2015-08-15 16:00:42 -04:00
|
|
|
names.push_back(zone.name());
|
2016-08-05 20:16:09 -04:00
|
|
|
for (auto& link : db.links)
|
2015-08-15 16:00:42 -04:00
|
|
|
names.push_back(link.name());
|
|
|
|
std::sort(names.begin(), names.end());
|
2017-06-04 14:58:57 -04:00
|
|
|
#endif // !USE_OS_TZDB
|
2016-04-17 21:51:30 -04:00
|
|
|
std::cout << db.version << "\n\n";
|
2015-08-15 16:00:42 -04:00
|
|
|
for (auto const& name : names)
|
|
|
|
{
|
|
|
|
std::cout << name << '\n';
|
|
|
|
auto z = locate_zone(name);
|
2024-05-08 17:15:38 +02:00
|
|
|
auto begin = sys_days(jan/1/date::year::min()) + seconds{0};
|
2016-06-03 21:10:53 +12:00
|
|
|
auto end = sys_days(jan/1/2035) + seconds{0};
|
2016-05-08 22:59:39 -04:00
|
|
|
auto info = z->get_info(begin);
|
2015-08-15 16:00:42 -04:00
|
|
|
std::cout << "Initially: ";
|
2016-06-03 21:10:53 +12:00
|
|
|
if (info.offset >= seconds{0})
|
2015-08-15 16:00:42 -04:00
|
|
|
std::cout << '+';
|
|
|
|
std::cout << make_time(info.offset);
|
2016-06-03 21:10:53 +12:00
|
|
|
if (info.save == minutes{0})
|
2015-08-15 16:00:42 -04:00
|
|
|
std::cout << " standard ";
|
|
|
|
else
|
|
|
|
std::cout << " daylight ";
|
|
|
|
std::cout << info.abbrev << '\n';
|
2016-04-17 21:51:30 -04:00
|
|
|
test_info(z, info);
|
2015-08-15 16:00:42 -04:00
|
|
|
auto prev_offset = info.offset;
|
|
|
|
auto prev_abbrev = info.abbrev;
|
|
|
|
auto prev_save = info.save;
|
|
|
|
for (begin = info.end; begin < end; begin = info.end)
|
|
|
|
{
|
2016-05-08 22:59:39 -04:00
|
|
|
info = z->get_info(begin);
|
2016-04-17 21:51:30 -04:00
|
|
|
test_info(z, info);
|
2015-08-15 16:00:42 -04:00
|
|
|
if (info.offset == prev_offset && info.abbrev == prev_abbrev &&
|
|
|
|
info.save == prev_save)
|
|
|
|
continue;
|
|
|
|
auto dp = floor<days>(begin);
|
2024-05-08 17:15:38 +02:00
|
|
|
auto ymd = date::year_month_day(dp);
|
2015-08-15 16:00:42 -04:00
|
|
|
auto time = make_time(begin - dp);
|
2016-04-21 16:08:06 -04:00
|
|
|
std::cout << ymd << ' ' << time << "Z ";
|
2016-06-03 21:10:53 +12:00
|
|
|
if (info.offset >= seconds{0})
|
2015-08-15 16:00:42 -04:00
|
|
|
std::cout << '+';
|
|
|
|
std::cout << make_time(info.offset);
|
2016-06-03 21:10:53 +12:00
|
|
|
if (info.save == minutes{0})
|
2015-08-15 16:00:42 -04:00
|
|
|
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';
|
|
|
|
}
|
2016-06-02 00:52:32 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tzmain();
|
|
|
|
}
|
|
|
|
catch(const std::exception& ex)
|
|
|
|
{
|
|
|
|
std::cout << "An exception occured: " << ex.what() << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|