mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-02 20:24:27 +02:00
Remove static conversion functions from clocks
The free function converters are sufficient API.
This commit is contained in:
121
tz.h
121
tz.h
@@ -1016,17 +1016,6 @@ public:
|
|||||||
static CONSTDATA bool is_steady = true;
|
static CONSTDATA bool is_steady = true;
|
||||||
|
|
||||||
static time_point now() NOEXCEPT;
|
static time_point now() NOEXCEPT;
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
static
|
|
||||||
std::chrono::time_point<utc_clock,
|
|
||||||
typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
sys_to_utc(sys_time<Duration> t);
|
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
static
|
|
||||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
utc_to_sys(std::chrono::time_point<utc_clock, Duration> t);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
@@ -1034,33 +1023,27 @@ template <class Duration>
|
|||||||
|
|
||||||
using utc_seconds = utc_time<std::chrono::seconds>;
|
using utc_seconds = utc_time<std::chrono::seconds>;
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
inline
|
inline
|
||||||
utc_clock::time_point
|
|
||||||
utc_clock::now() NOEXCEPT
|
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
|
||||||
return sys_to_utc(system_clock::now());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
utc_clock::sys_to_utc(sys_time<Duration> t)
|
to_utc_time(sys_time<Duration> st)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using duration = typename std::common_type<Duration, seconds>::type;
|
using duration = typename std::common_type<Duration, seconds>::type;
|
||||||
auto const& leaps = get_tzdb().leaps;
|
auto const& leaps = get_tzdb().leaps;
|
||||||
auto const lt = std::upper_bound(leaps.begin(), leaps.end(), t);
|
auto const lt = std::upper_bound(leaps.begin(), leaps.end(), st);
|
||||||
return utc_time<duration>{t.time_since_epoch() + seconds{lt-leaps.begin()}};
|
return utc_time<duration>{st.time_since_epoch() + seconds{lt-leaps.begin()}};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
|
inline
|
||||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
utc_clock::utc_to_sys(utc_time<Duration> t)
|
to_sys_time(utc_time<Duration> ut)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using duration = typename std::common_type<Duration, seconds>::type;
|
using duration = typename std::common_type<Duration, seconds>::type;
|
||||||
auto const& leaps = get_tzdb().leaps;
|
auto const& leaps = get_tzdb().leaps;
|
||||||
auto tp = sys_time<duration>{t.time_since_epoch()};
|
auto tp = sys_time<duration>{ut.time_since_epoch()};
|
||||||
if (tp >= leaps.front())
|
if (tp >= leaps.front())
|
||||||
{
|
{
|
||||||
auto const lt = std::upper_bound(leaps.begin(), leaps.end(), tp);
|
auto const lt = std::upper_bound(leaps.begin(), leaps.end(), tp);
|
||||||
@@ -1076,20 +1059,12 @@ utc_clock::utc_to_sys(utc_time<Duration> t)
|
|||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
inline
|
inline
|
||||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
utc_clock::time_point
|
||||||
to_sys_time(utc_time<Duration> ut)
|
utc_clock::now() NOEXCEPT
|
||||||
{
|
{
|
||||||
return utc_clock::utc_to_sys(ut);
|
using namespace std::chrono;
|
||||||
}
|
return to_utc_time(system_clock::now());
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
inline
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
to_utc_time(sys_time<Duration> st)
|
|
||||||
{
|
|
||||||
return utc_clock::sys_to_utc(st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class CharT, class Traits, class Duration>
|
template <class CharT, class Traits, class Duration>
|
||||||
@@ -1132,17 +1107,6 @@ public:
|
|||||||
static const bool is_steady = true;
|
static const bool is_steady = true;
|
||||||
|
|
||||||
static time_point now() NOEXCEPT;
|
static time_point now() NOEXCEPT;
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
static
|
|
||||||
std::chrono::time_point<tai_clock,
|
|
||||||
typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
utc_to_tai(utc_time<Duration> t);
|
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
static
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
tai_to_utc(std::chrono::time_point<tai_clock, Duration> t);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
@@ -1151,18 +1115,9 @@ template <class Duration>
|
|||||||
using tai_seconds = tai_time<std::chrono::seconds>;
|
using tai_seconds = tai_time<std::chrono::seconds>;
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
inline
|
||||||
tai_clock::utc_to_tai(utc_time<Duration> t)
|
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
|
||||||
using duration = typename std::common_type<Duration, seconds>::type;
|
|
||||||
return tai_time<duration>{t.time_since_epoch()} +
|
|
||||||
(sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
tai_clock::tai_to_utc(tai_time<Duration> t)
|
to_utc_time(tai_time<Duration> t)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using duration = typename std::common_type<Duration, seconds>::type;
|
using duration = typename std::common_type<Duration, seconds>::type;
|
||||||
@@ -1170,20 +1125,15 @@ tai_clock::tai_to_utc(tai_time<Duration> t)
|
|||||||
(sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10});
|
(sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
inline
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
to_utc_time(tai_time<Duration> t)
|
|
||||||
{
|
|
||||||
return tai_clock::tai_to_utc(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
inline
|
inline
|
||||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
to_tai_time(utc_time<Duration> t)
|
to_tai_time(utc_time<Duration> t)
|
||||||
{
|
{
|
||||||
return tai_clock::utc_to_tai(t);
|
using namespace std::chrono;
|
||||||
|
using duration = typename std::common_type<Duration, seconds>::type;
|
||||||
|
return tai_time<duration>{t.time_since_epoch()} +
|
||||||
|
(sys_days{year{1970}/jan/1} - sys_days{year{1958}/jan/1} + seconds{10});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -1217,17 +1167,6 @@ public:
|
|||||||
static const bool is_steady = true;
|
static const bool is_steady = true;
|
||||||
|
|
||||||
static time_point now() NOEXCEPT;
|
static time_point now() NOEXCEPT;
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
static
|
|
||||||
std::chrono::time_point<gps_clock,
|
|
||||||
typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
utc_to_gps(utc_time<Duration> t);
|
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
static
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
gps_to_utc(std::chrono::time_point<gps_clock, Duration> t);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
@@ -1236,18 +1175,9 @@ template <class Duration>
|
|||||||
using gps_seconds = gps_time<std::chrono::seconds>;
|
using gps_seconds = gps_time<std::chrono::seconds>;
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
inline
|
||||||
gps_clock::utc_to_gps(utc_time<Duration> t)
|
|
||||||
{
|
|
||||||
using namespace std::chrono;
|
|
||||||
using duration = typename std::common_type<Duration, seconds>::type;
|
|
||||||
return gps_time<duration>{t.time_since_epoch()} -
|
|
||||||
(sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
gps_clock::gps_to_utc(gps_time<Duration> t)
|
to_utc_time(gps_time<Duration> t)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
using duration = typename std::common_type<Duration, seconds>::type;
|
using duration = typename std::common_type<Duration, seconds>::type;
|
||||||
@@ -1255,20 +1185,15 @@ gps_clock::gps_to_utc(gps_time<Duration> t)
|
|||||||
(sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9});
|
(sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Duration>
|
|
||||||
inline
|
|
||||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
to_utc_time(gps_time<Duration> t)
|
|
||||||
{
|
|
||||||
return gps_clock::gps_to_utc(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
inline
|
inline
|
||||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||||
to_gps_time(utc_time<Duration> t)
|
to_gps_time(utc_time<Duration> t)
|
||||||
{
|
{
|
||||||
return gps_clock::utc_to_gps(t);
|
using namespace std::chrono;
|
||||||
|
using duration = typename std::common_type<Duration, seconds>::type;
|
||||||
|
return gps_time<duration>{t.time_since_epoch()} -
|
||||||
|
(sys_days{year{1980}/jan/sun[1]} - sys_days{year{1970}/jan/1} + seconds{9});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
Reference in New Issue
Block a user