Fix DateTime::GetDate calculations

#2089 #2086
This commit is contained in:
Wojtek Figat
2024-01-05 11:13:41 +01:00
parent 6fb6769574
commit 976d0992df
2 changed files with 27 additions and 3 deletions

View File

@@ -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<float>(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;

View File

@@ -0,0 +1,26 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "Engine/Core/Types/DateTime.h"
#include <ThirdParty/catch2/catch.hpp>
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);
}
}