Core/Time: Fix operator<< with negative values not using units

This commit is contained in:
SirLynix
2024-02-01 12:57:29 +01:00
parent 369f273894
commit 5db0c4ed09
3 changed files with 19 additions and 18 deletions

View File

@@ -3,6 +3,8 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Time.hpp>
#include <cstdlib>
#include <ostream>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/Win32/TimeImpl.hpp>
@@ -31,6 +33,21 @@ namespace Nz
}
}
std::ostream& operator<<(std::ostream& out, Time time)
{
Int64 ns = time.AsNanoseconds();
Int64 nsAbs = std::llabs(ns);
if (nsAbs > 1'000'000'000)
return out << time.AsSeconds<double>() << "s";
else if (nsAbs > 1'000'000)
return out << ns / 1'000'000.0 << "ms";
else if (nsAbs > 1'000)
return out << ns / 1'000.0 << "us";
else
return out << ns << "ns";
}
GetElapsedTimeFunction GetElapsedMilliseconds = PlatformImpl::GetElapsedMillisecondsImpl;
GetElapsedTimeFunction GetElapsedNanoseconds = NAZARA_ANONYMOUS_NAMESPACE_PREFIX(GetElapsedNanosecondsFirstRun);
}