forked from HowardHinnant/date
Create local and system time types for timezone functions.
* Add sys_time. * Add sys_days. * Add sys_seconds. * Add local_time. * Add local_days. * Add local_seconds. * Rename day_point to sys_days. * Rename Zone to time_zone.
This commit is contained in:
Binary file not shown.
+34
-29
@@ -2,38 +2,42 @@
|
||||
#include <iostream>
|
||||
|
||||
void
|
||||
test_info(const date::Zone* zone, const date::Info& info)
|
||||
test_info(const date::time_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 ;
|
||||
auto mid = begin + (end - begin) /2;
|
||||
using sys_microseconds = sys_time<microseconds>;
|
||||
using zoned_microseconds = zoned_time<microseconds>;
|
||||
using local_microseconds = local_time<microseconds>;
|
||||
zoned_microseconds local{zone};
|
||||
|
||||
if (begin > day_point{jan/1/1700})
|
||||
if (begin > sys_days{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})
|
||||
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})
|
||||
{
|
||||
assert(zone->to_sys(local) == begin);
|
||||
auto imaginary = prev_local + (local - seconds{1} - prev_local) / 2;
|
||||
assert(sys_microseconds{local} == begin);
|
||||
try
|
||||
{
|
||||
zone->to_sys(imaginary);
|
||||
local = plocal + (slocal - seconds{1} - plocal) / 2;
|
||||
assert(false);
|
||||
}
|
||||
catch (const nonexistent_local_time&)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (prev_local > local - seconds{1})
|
||||
else if (plocal > slocal - seconds{1})
|
||||
{
|
||||
auto ambiguous = local - seconds{1} +
|
||||
(prev_local - (local - seconds{1})) / 2;
|
||||
try
|
||||
{
|
||||
zone->to_sys(ambiguous);
|
||||
local = slocal - seconds{1} + (plocal - (slocal - seconds{1})) / 2;
|
||||
assert(false);
|
||||
}
|
||||
catch (const ambiguous_local_time&)
|
||||
@@ -42,33 +46,34 @@ test_info(const date::Zone* zone, const date::Info& info)
|
||||
}
|
||||
}
|
||||
|
||||
auto local = zone->to_local(mid).first;
|
||||
assert(zone->to_sys(local) == mid);
|
||||
local = mid;
|
||||
assert(sys_microseconds{local} == mid);
|
||||
|
||||
if (end < day_point{jan/1/3000})
|
||||
if (end < sys_days{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})
|
||||
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})
|
||||
{
|
||||
auto ambiguous = next_local + (local + microseconds{1} - next_local) / 2;
|
||||
try
|
||||
{
|
||||
zone->to_sys(ambiguous);
|
||||
local = nlocal + (slocal + microseconds{1} - nlocal) / 2;
|
||||
assert(false);
|
||||
}
|
||||
catch (const ambiguous_local_time&)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (next_local > local + microseconds{1})
|
||||
else if (nlocal > slocal + microseconds{1})
|
||||
{
|
||||
assert(zone->to_sys(local) == end);
|
||||
auto imaginary = local + microseconds{1} +
|
||||
(next_local - (local + microseconds{1})) / 2;
|
||||
assert(sys_microseconds{local} == end);
|
||||
try
|
||||
{
|
||||
zone->to_sys(imaginary);
|
||||
local = slocal + microseconds{1} +
|
||||
(nlocal - (slocal + microseconds{1})) / 2;
|
||||
assert(false);
|
||||
}
|
||||
catch (const nonexistent_local_time&)
|
||||
@@ -96,8 +101,8 @@ main()
|
||||
{
|
||||
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 begin = sys_days(jan/1/year::min()) + 0s;
|
||||
auto end = sys_days(jan/1/2035) + 0s;
|
||||
auto info = z->get_info(begin, tz::utc);
|
||||
std::cout << "Initially: ";
|
||||
if (info.offset >= 0s)
|
||||
@@ -122,7 +127,7 @@ main()
|
||||
auto dp = floor<days>(begin);
|
||||
auto ymd = year_month_day(dp);
|
||||
auto time = make_time(begin - dp);
|
||||
std::cout << ymd << 'T' << time << "Z ";
|
||||
std::cout << ymd << ' ' << time << "Z ";
|
||||
if (info.offset >= 0s)
|
||||
std::cout << '+';
|
||||
std::cout << make_time(info.offset);
|
||||
|
||||
@@ -6,10 +6,10 @@ main()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace date;
|
||||
static_assert( is_nothrow_destructible<Zone>{}, "");
|
||||
static_assert(!is_default_constructible<Zone>{}, "");
|
||||
static_assert(!is_copy_constructible<Zone>{}, "");
|
||||
static_assert(!is_copy_assignable<Zone>{}, "");
|
||||
static_assert( is_nothrow_move_constructible<Zone>{}, "");
|
||||
static_assert( is_nothrow_move_assignable<Zone>{}, "");
|
||||
static_assert( is_nothrow_destructible<time_zone>{}, "");
|
||||
static_assert(!is_default_constructible<time_zone>{}, "");
|
||||
static_assert(!is_copy_constructible<time_zone>{}, "");
|
||||
static_assert(!is_copy_assignable<time_zone>{}, "");
|
||||
static_assert( is_nothrow_move_constructible<time_zone>{}, "");
|
||||
static_assert( is_nothrow_move_assignable<time_zone>{}, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user