mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-27 23:14:38 +00:00
Implemented "ConvertFromUnix" (not sure if it's right but I guess it works?)
This commit is contained in:
parent
3f3b636caf
commit
ad16d361dc
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user