Implemented "ConvertFromUnix" (not sure if it's right but I guess it works?)

This commit is contained in:
Alex 2023-01-09 03:30:13 +02:00
parent 3f3b636caf
commit ad16d361dc
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 35 additions and 1 deletions

View File

@ -1,4 +1,5 @@
#include <time.hpp>
#include <debug.h>
#include <io.h>
namespace Time
@ -38,4 +39,36 @@ namespace Time
#endif
return tm;
}
Clock ConvertFromUnix(int Timestamp)
{
Clock result;
if (Timestamp == 0)
return result;
int SecondsSinceYearStart = Timestamp % (60 * 60 * 24 * 365);
result.Year = Timestamp / (60 * 60 * 24 * 365);
result.Month = SecondsSinceYearStart / (60 * 60 * 24 * 30);
result.Day = SecondsSinceYearStart / (60 * 60 * 24);
result.Hour = SecondsSinceYearStart / (60 * 60);
result.Minute = SecondsSinceYearStart / 60;
result.Second = SecondsSinceYearStart;
#ifdef DEBUG
int DaysInYear;
if (result.Year % 4 != 0)
DaysInYear = 365;
else if (result.Year % 100 != 0)
DaysInYear = 366;
else if (result.Year % 400 == 0)
DaysInYear = 366;
else
DaysInYear = 365;
debug("Days in year: %d", DaysInYear);
#endif
return result;
}
}

View File

@ -7,11 +7,12 @@ namespace Time
{
struct Clock
{
uint64_t Year, Month, Day, Hour, Minute, Second;
int Year, Month, Day, Hour, Minute, Second;
uint64_t Counter;
};
Clock ReadClock();
Clock ConvertFromUnix(int Timestamp);
class time
{