@@ -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;
|
||||
|
||||
26
Source/Engine/Tests/TestTime.cpp
Normal file
26
Source/Engine/Tests/TestTime.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user