diff --git a/Source/Engine/Core/Types/DateTime.cpp b/Source/Engine/Core/Types/DateTime.cpp index a0d873b43..3141cd52d 100644 --- a/Source/Engine/Core/Types/DateTime.cpp +++ b/Source/Engine/Core/Types/DateTime.cpp @@ -35,8 +35,7 @@ void DateTime::GetDate(int32& year, int32& month, int32& day) const // Based on: // Fliegel, H. F. and van Flandern, T. C., // Communications of the ACM, Vol. 11, No. 10 (October 1968). - - int32 l = Math::FloorToInt(static_cast(GetJulianDay() + 0.5)) + 68569; + int32 l = Math::FloorToInt((float)(GetDate().GetJulianDay() + 0.5)) + 68569; const int32 n = 4 * l / 146097; l = l - (146097 * n + 3) / 4; int32 i = 4000 * (l + 1) / 1461001; @@ -46,7 +45,6 @@ void DateTime::GetDate(int32& year, int32& month, int32& day) const l = j / 11; j = j + 2 - 12 * l; i = 100 * (n - 49) + i + l; - year = i; month = j; day = k; diff --git a/Source/Engine/Tests/TestTime.cpp b/Source/Engine/Tests/TestTime.cpp new file mode 100644 index 000000000..0419c5e13 --- /dev/null +++ b/Source/Engine/Tests/TestTime.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. + +#include "Engine/Core/Types/DateTime.h" +#include + +TEST_CASE("DateTime") +{ + SECTION("Test Convertion") + { + constexpr int year = 2023; + constexpr int month = 12; + constexpr int day = 16; + constexpr int hour = 23; + constexpr int minute = 50; + constexpr int second = 13; + constexpr int millisecond = 5; + const DateTime dt1(year, month, day, hour, minute, second, millisecond); + CHECK(dt1.GetYear() == year); + CHECK(dt1.GetMonth() == month); + CHECK(dt1.GetDay() == day); + CHECK(dt1.GetHour() == hour); + CHECK(dt1.GetMinute() == minute); + CHECK(dt1.GetSecond() == second); + CHECK(dt1.GetMillisecond() == millisecond); + } +}