Core/Time: Add support for AsSeconds<integer>
This commit is contained in:
parent
96618cbb5b
commit
602361e8e1
|
|
@ -23,9 +23,16 @@ namespace Nz
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr T Time::AsSeconds() const
|
constexpr T Time::AsSeconds() const
|
||||||
{
|
{
|
||||||
static_assert(std::is_floating_point_v<T>);
|
if constexpr (std::is_floating_point_v<T>)
|
||||||
// TODO: Improve precision
|
{
|
||||||
return AsMicroseconds() / T(1'000'000.0) + (m_nanoseconds % 1000) / T(1'000'000'000);
|
// TODO: Improve precision
|
||||||
|
return AsMicroseconds() / T(1'000'000.0) + (m_nanoseconds % 1000) / T(1'000'000'000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static_assert(std::is_integral_v<T>);
|
||||||
|
return SafeCast<T>(AsMicroseconds() / Int64(1'000'000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Int64 Time::AsMicroseconds() const
|
constexpr Int64 Time::AsMicroseconds() const
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ SCENARIO("Time", "[CORE][Time]")
|
||||||
CHECK(time.AsMicroseconds() == 1'000'000);
|
CHECK(time.AsMicroseconds() == 1'000'000);
|
||||||
CHECK(time.AsMilliseconds() == 1'000);
|
CHECK(time.AsMilliseconds() == 1'000);
|
||||||
CHECK(time.AsSeconds() == 1.f);
|
CHECK(time.AsSeconds() == 1.f);
|
||||||
|
CHECK(time.AsSeconds<int>() == 1);
|
||||||
CHECK(time == Nz::Time::Second());
|
CHECK(time == Nz::Time::Second());
|
||||||
CHECK(time == Nz::Time::Seconds(1.f));
|
CHECK(time == Nz::Time::Seconds(1.f));
|
||||||
CHECK(time == Nz::Time::Milliseconds(1'000));
|
CHECK(time == Nz::Time::Milliseconds(1'000));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue