forked from HowardHinnant/date
Reversed order of arguments to clock_time_conversion.
Now the order of argument matches the clock_cast function. The test only is_clock_castable trait still matches is_convertible order of arguments.
This commit is contained in:
committed by
Howard Hinnant
parent
7c69f1570d
commit
543315b700
@@ -39,7 +39,7 @@ struct mil_clock
|
||||
|
||||
template<typename Duration>
|
||||
static
|
||||
std::chrono::time_point<std::chrono::system_clock, std::common_type_t<Duration, date::days>>
|
||||
std::chrono::time_point<std::chrono::system_clock, std::common_type_t<Duration, date::days>>
|
||||
to_sys(std::chrono::time_point<mil_clock, Duration> const& tp)
|
||||
{
|
||||
++conversions;
|
||||
@@ -66,7 +66,7 @@ struct mil_clock
|
||||
date::sys_days const mil_clock::epoch;
|
||||
|
||||
// traits example
|
||||
struct s2s_clock
|
||||
struct s2s_clock
|
||||
{
|
||||
using duration = std::chrono::system_clock::duration;
|
||||
using rep = duration::rep;
|
||||
@@ -75,7 +75,7 @@ struct s2s_clock
|
||||
|
||||
template<typename Duration>
|
||||
static
|
||||
std::chrono::time_point<std::chrono::system_clock, Duration>
|
||||
std::chrono::time_point<std::chrono::system_clock, Duration>
|
||||
to_sys(std::chrono::time_point<s2s_clock, Duration> const& tp)
|
||||
{
|
||||
++conversions;
|
||||
@@ -84,7 +84,7 @@ struct s2s_clock
|
||||
|
||||
template<typename Duration>
|
||||
static
|
||||
std::chrono::time_point<s2s_clock, Duration>
|
||||
std::chrono::time_point<s2s_clock, Duration>
|
||||
from_sys(std::chrono::time_point<std::chrono::system_clock, Duration> const& tp)
|
||||
{
|
||||
++conversions;
|
||||
@@ -100,7 +100,7 @@ struct s2s_clock
|
||||
namespace date
|
||||
{
|
||||
template<>
|
||||
struct clock_time_conversion<s2s_clock, mil_clock>
|
||||
struct clock_time_conversion<mil_clock, s2s_clock>
|
||||
{
|
||||
template<typename Duration>
|
||||
std::chrono::time_point<mil_clock, std::common_type_t<Duration, date::days>>
|
||||
@@ -123,7 +123,7 @@ main()
|
||||
{
|
||||
sys_days st(1997_y/dec/12);
|
||||
auto mt = mil_clock::from_sys(st);
|
||||
|
||||
|
||||
assert(clock_cast<mil_clock>(mt) == mt);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ main()
|
||||
auto mt = mil_clock::from_sys(st);
|
||||
|
||||
assert(clock_cast<mil_clock>(st) == mt);
|
||||
assert(clock_cast<sys_clock>(mt) == st);
|
||||
assert(clock_cast<sys_clock>(mt) == st);
|
||||
}
|
||||
|
||||
// mil <-> utc
|
||||
@@ -143,7 +143,7 @@ main()
|
||||
auto ut = utc_clock::from_sys(st);
|
||||
|
||||
assert(clock_cast<mil_clock>(ut) == mt);
|
||||
assert(clock_cast<utc_clock>(mt) == ut);
|
||||
assert(clock_cast<utc_clock>(mt) == ut);
|
||||
}
|
||||
|
||||
// mil <-> tai
|
||||
@@ -179,7 +179,7 @@ main()
|
||||
assert(clock_cast<mil_clock>(s2t) == mt);
|
||||
assert(conversions == 1);
|
||||
|
||||
//uses sys_clock
|
||||
//uses sys_clock
|
||||
conversions = 0;
|
||||
assert(clock_cast<s2s_clock>(mt) == s2t);
|
||||
assert(conversions == 2);
|
||||
|
@@ -34,7 +34,7 @@ main()
|
||||
auto ut = utc_clock::from_sys(st);
|
||||
|
||||
assert(to_utc_time(st) == ut);
|
||||
assert(to_sys_time(ut) == st);
|
||||
assert(to_sys_time(ut) == st);
|
||||
}
|
||||
|
||||
// tai <-> utc
|
||||
@@ -77,7 +77,7 @@ main()
|
||||
assert(to_sys_time(gt) == st);
|
||||
}
|
||||
|
||||
// tai <-> gps
|
||||
// tai <-> gps
|
||||
{
|
||||
sys_days st(1997_y/dec/12);
|
||||
auto ut = utc_clock::from_sys(st);
|
||||
|
@@ -25,7 +25,7 @@
|
||||
#include <cassert>
|
||||
|
||||
template<typename SourceClock, typename DestClock, typename = void>
|
||||
struct is_clock_castable
|
||||
struct is_clock_castable
|
||||
: std::false_type
|
||||
{};
|
||||
|
||||
@@ -36,7 +36,7 @@ struct is_clock_castable<SourceClock, DestClock, decltype(date::clock_cast<DestC
|
||||
|
||||
|
||||
//Clock based on steady clock, not related to wall time (sys_clock/utc_clock)
|
||||
struct steady_based_clock
|
||||
struct steady_based_clock
|
||||
{
|
||||
using duration = std::chrono::steady_clock::duration;
|
||||
using rep = duration::rep;
|
||||
@@ -54,7 +54,7 @@ struct steady_based_clock
|
||||
namespace date
|
||||
{
|
||||
template<>
|
||||
struct clock_time_conversion<steady_based_clock, std::chrono::steady_clock>
|
||||
struct clock_time_conversion<std::chrono::steady_clock, steady_based_clock>
|
||||
{
|
||||
template<typename Duration>
|
||||
std::chrono::time_point<std::chrono::steady_clock, Duration>
|
||||
@@ -66,7 +66,7 @@ namespace date
|
||||
};
|
||||
|
||||
template<>
|
||||
struct clock_time_conversion<std::chrono::steady_clock, steady_based_clock>
|
||||
struct clock_time_conversion<steady_based_clock, std::chrono::steady_clock>
|
||||
{
|
||||
template<typename Duration>
|
||||
std::chrono::time_point<steady_based_clock, Duration>
|
||||
@@ -78,7 +78,7 @@ namespace date
|
||||
};
|
||||
}
|
||||
|
||||
//Ambigous clocks both providing to/from_sys and to/from_utc
|
||||
//Ambigous clocks both providing to/from_sys and to/from_utc
|
||||
//They are mock_ups just returning zero time_point
|
||||
struct amb1_clock
|
||||
{
|
||||
@@ -87,7 +87,7 @@ struct amb1_clock
|
||||
using period = duration::period;
|
||||
using time_point = std::chrono::time_point<amb1_clock>;
|
||||
|
||||
static time_point now()
|
||||
static time_point now()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@@ -132,7 +132,7 @@ struct amb2_clock
|
||||
using period = duration::period;
|
||||
using time_point = std::chrono::time_point<amb2_clock>;
|
||||
|
||||
static time_point now()
|
||||
static time_point now()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
@@ -174,7 +174,7 @@ namespace date
|
||||
{
|
||||
//Disambiguates that sys_clock is preffered
|
||||
template<>
|
||||
struct clock_time_conversion<amb2_clock, amb1_clock>
|
||||
struct clock_time_conversion<amb1_clock, amb2_clock>
|
||||
{
|
||||
template<typename Duration>
|
||||
std::chrono::time_point<amb1_clock, Duration>
|
||||
@@ -214,7 +214,7 @@ main()
|
||||
{
|
||||
auto s1 = steady_clock::time_point(steady_clock::duration(200));
|
||||
auto s2 = steady_based_clock::time_point(steady_based_clock::duration(200));
|
||||
|
||||
|
||||
assert(clock_cast<steady_based_clock>(s1) == s2);
|
||||
assert(clock_cast<steady_clock>(s2) == s1);
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ main()
|
||||
sys_days st(1997_y/dec/12);
|
||||
auto ut = utc_clock::from_sys(st);
|
||||
auto tt = tai_clock::from_utc(ut);
|
||||
|
||||
|
||||
assert(clock_cast<sys_clock>(st) == st);
|
||||
assert(clock_cast<utc_clock>(ut) == ut);
|
||||
assert(clock_cast<tai_clock>(tt) == tt);
|
||||
@@ -46,7 +46,7 @@ main()
|
||||
auto ut = utc_clock::from_sys(st);
|
||||
|
||||
assert(clock_cast<utc_clock>(st) == ut);
|
||||
assert(clock_cast<sys_clock>(ut) == st);
|
||||
assert(clock_cast<sys_clock>(ut) == st);
|
||||
}
|
||||
|
||||
// tai <-> utc
|
||||
@@ -89,7 +89,7 @@ main()
|
||||
assert(clock_cast<sys_clock>(gt) == st);
|
||||
}
|
||||
|
||||
// tai <-> gps
|
||||
// tai <-> gps
|
||||
{
|
||||
sys_days st(1997_y/dec/12);
|
||||
auto ut = utc_clock::from_sys(st);
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "tz.h"
|
||||
|
||||
struct bad_clock
|
||||
struct bad_clock
|
||||
{
|
||||
using duration = std::chrono::system_clock::duration;
|
||||
using rep = duration::rep;
|
||||
@@ -31,7 +31,7 @@ struct bad_clock
|
||||
|
||||
template<typename Duration>
|
||||
static
|
||||
int
|
||||
int
|
||||
to_sys(std::chrono::time_point<bad_clock, Duration> const& tp)
|
||||
{
|
||||
return tp.time_since_epoch().count();
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "tz.h"
|
||||
|
||||
struct bad_clock
|
||||
struct bad_clock
|
||||
{
|
||||
using duration = std::chrono::system_clock::duration;
|
||||
using rep = duration::rep;
|
||||
|
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "tz.h"
|
||||
|
||||
struct bad_clock
|
||||
struct bad_clock
|
||||
{
|
||||
using duration = std::chrono::system_clock::duration;
|
||||
using rep = duration::rep;
|
||||
@@ -31,7 +31,7 @@ struct bad_clock
|
||||
|
||||
template<typename Duration>
|
||||
static
|
||||
date::utc_time<Duration>
|
||||
date::utc_time<Duration>
|
||||
to_sys(std::chrono::time_point<bad_clock, Duration> const& tp)
|
||||
{
|
||||
return utc_time<Duration>(tp.time_since_epoch());
|
||||
|
Reference in New Issue
Block a user