2018-06-10 19:01:30 +02:00
|
|
|
#include <chrono>
|
|
|
|
#include "date/tz.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
using namespace date;
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
2018-06-10 23:38:21 +02:00
|
|
|
// self
|
|
|
|
{
|
|
|
|
auto ls = local_days{1970_y/01/01_d};
|
|
|
|
assert(clock_cast<local_t>(ls) == ls);
|
|
|
|
}
|
|
|
|
|
2018-06-10 19:01:30 +02:00
|
|
|
/// sys epoch
|
|
|
|
{
|
|
|
|
auto ls = local_days{1970_y/01/01_d};
|
|
|
|
auto st = clock_cast<system_clock>(ls);
|
|
|
|
assert(clock_cast<local_t>(st) == ls);
|
2018-06-10 23:03:54 +02:00
|
|
|
assert(st.time_since_epoch() == seconds(0));
|
2018-06-10 19:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// sys 2000 case
|
|
|
|
{
|
|
|
|
auto ls = local_days{2000_y/01/01_d};
|
|
|
|
auto st = clock_cast<system_clock>(ls);
|
|
|
|
assert(clock_cast<local_t>(st) == ls);
|
2018-06-10 23:03:54 +02:00
|
|
|
assert(st.time_since_epoch() == seconds(946684800));
|
2018-06-10 19:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// utc epoch
|
|
|
|
{
|
|
|
|
auto lu = local_days{1970_y/01/01_d};
|
|
|
|
auto ut = clock_cast<utc_clock>(lu);
|
|
|
|
assert(clock_cast<local_t>(ut) == lu);
|
2018-06-10 23:03:54 +02:00
|
|
|
assert(ut.time_since_epoch() == seconds(0));
|
2018-06-10 19:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// utc paper example
|
|
|
|
{
|
|
|
|
auto lu = local_days{2000_y/01/01_d};
|
|
|
|
auto ut = clock_cast<utc_clock>(lu);
|
|
|
|
assert(clock_cast<local_t>(ut) == lu);
|
2018-06-10 23:03:54 +02:00
|
|
|
assert(ut.time_since_epoch() == seconds(946684822));
|
2018-06-10 19:01:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// tai epoch
|
|
|
|
{
|
|
|
|
auto lt = local_days{1958_y/01/01_d};
|
|
|
|
auto tt = clock_cast<tai_clock>(lt);
|
|
|
|
assert(clock_cast<local_t>(tt) == lt);
|
2018-06-10 23:03:54 +02:00
|
|
|
assert(tt.time_since_epoch() == seconds(0));
|
2018-06-10 19:01:30 +02:00
|
|
|
|
2018-06-10 23:03:54 +02:00
|
|
|
auto lu = local_days{1958_y/01/01_d} - seconds(10);
|
2018-06-10 19:01:30 +02:00
|
|
|
auto ut = clock_cast<utc_clock>(lu);
|
|
|
|
assert(clock_cast<tai_clock>(ut) == tt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// tai paper example
|
|
|
|
{
|
2018-06-10 23:03:54 +02:00
|
|
|
auto lt = local_days{2000_y/01/01_d} + seconds(32);
|
2018-06-10 19:01:30 +02:00
|
|
|
auto tt = clock_cast<tai_clock>(lt);
|
|
|
|
assert(clock_cast<local_t>(tt) == lt);
|
|
|
|
|
|
|
|
auto lu = local_days{2000_y/01/01_d};
|
|
|
|
auto ut = clock_cast<utc_clock>(lu);
|
|
|
|
assert(clock_cast<tai_clock>(ut) == tt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// gps epoch
|
|
|
|
{
|
|
|
|
auto lg = local_days{1980_y/01/Sunday[1]};
|
|
|
|
auto gt = clock_cast<gps_clock>(lg);
|
|
|
|
assert(clock_cast<local_t>(gt) == lg);
|
2018-06-10 23:03:54 +02:00
|
|
|
assert(gt.time_since_epoch() == seconds(0));
|
2018-06-10 19:01:30 +02:00
|
|
|
|
|
|
|
auto lu = local_days{1980_y/01/Sunday[1]};
|
|
|
|
auto ut = clock_cast<utc_clock>(lu);
|
|
|
|
assert(clock_cast<gps_clock>(ut) == gt);
|
|
|
|
|
2018-06-10 23:03:54 +02:00
|
|
|
auto lt = local_days{1980_y/01/Sunday[1]} + seconds(19);
|
2018-06-10 19:01:30 +02:00
|
|
|
auto tt = clock_cast<tai_clock>(lt);
|
|
|
|
assert(clock_cast<gps_clock>(tt) == gt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// gps 2000 example
|
|
|
|
{
|
|
|
|
auto lg = local_days{2000_y/01/01_d};
|
|
|
|
auto gt = clock_cast<gps_clock>(lg);
|
|
|
|
assert(clock_cast<local_t>(gt) == lg);
|
|
|
|
|
2018-06-10 23:03:54 +02:00
|
|
|
auto lu = local_days{2000_y/01/01_d} - seconds(13);
|
2018-06-10 19:01:30 +02:00
|
|
|
auto ut = clock_cast<utc_clock>(lu);
|
|
|
|
assert(clock_cast<gps_clock>(ut) == gt);
|
|
|
|
|
2018-06-10 23:03:54 +02:00
|
|
|
auto lt = local_days{2000_y/01/01_d} + seconds(19);
|
2018-06-10 19:01:30 +02:00
|
|
|
auto tt = clock_cast<tai_clock>(lt);
|
|
|
|
assert(clock_cast<gps_clock>(tt) == gt);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|