mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-30 00:08:03 +00:00
Fixed ConvertFromUnix()
This commit is contained in:
parent
744895afd6
commit
4d279f0d12
@ -43,31 +43,46 @@ namespace Time
|
|||||||
Clock ConvertFromUnix(int Timestamp)
|
Clock ConvertFromUnix(int Timestamp)
|
||||||
{
|
{
|
||||||
Clock result;
|
Clock result;
|
||||||
if (Timestamp == 0)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
int SecondsSinceYearStart = Timestamp % (60 * 60 * 24 * 365);
|
uint64_t Seconds = Timestamp;
|
||||||
|
uint64_t Minutes = Seconds / 60;
|
||||||
|
uint64_t Hours = Minutes / 60;
|
||||||
|
uint64_t Days = Hours / 24;
|
||||||
|
|
||||||
result.Year = Timestamp / (60 * 60 * 24 * 365);
|
result.Year = 1970;
|
||||||
result.Month = SecondsSinceYearStart / (60 * 60 * 24 * 30);
|
while (Days >= 365)
|
||||||
result.Day = SecondsSinceYearStart / (60 * 60 * 24);
|
{
|
||||||
result.Hour = SecondsSinceYearStart / (60 * 60);
|
if (result.Year % 4 == 0 && (result.Year % 100 != 0 || result.Year % 400 == 0))
|
||||||
result.Minute = SecondsSinceYearStart / 60;
|
{
|
||||||
result.Second = SecondsSinceYearStart;
|
if (Days >= 366)
|
||||||
|
{
|
||||||
|
Days -= 366;
|
||||||
|
result.Year++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Days -= 365;
|
||||||
|
result.Year++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
int DaysInMonth[] = {31, result.Year % 4 == 0 ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
int DaysInYear;
|
for (result.Month = 0; result.Month < 12; result.Month++)
|
||||||
if (result.Year % 4 != 0)
|
{
|
||||||
DaysInYear = 365;
|
if (Days < DaysInMonth[result.Month])
|
||||||
else if (result.Year % 100 != 0)
|
break;
|
||||||
DaysInYear = 366;
|
Days -= DaysInMonth[result.Month];
|
||||||
else if (result.Year % 400 == 0)
|
}
|
||||||
DaysInYear = 366;
|
result.Month++;
|
||||||
else
|
|
||||||
DaysInYear = 365;
|
|
||||||
debug("Days in year: %d", DaysInYear);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
result.Day = static_cast<int>(Days) + 1;
|
||||||
|
result.Hour = static_cast<int>(Hours % 24);
|
||||||
|
result.Minute = static_cast<int>(Minutes % 60);
|
||||||
|
result.Second = static_cast<int>(Seconds % 60);
|
||||||
|
result.Counter = static_cast<uint64_t>(Timestamp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ namespace NetworkInterfaceManager
|
|||||||
udp->Bind(NTP_Socket, ntp);
|
udp->Bind(NTP_Socket, ntp);
|
||||||
int UnixTimestamp = ntp->ReadTime();
|
int UnixTimestamp = ntp->ReadTime();
|
||||||
Time::Clock time = Time::ConvertFromUnix(UnixTimestamp);
|
Time::Clock time = Time::ConvertFromUnix(UnixTimestamp);
|
||||||
DbgWriteScreen("NTP: %d - %d.%d.%d %d:%d:%d", UnixTimestamp,
|
DbgWriteScreen("NTP: %d - %d.%d.%d %d:%d:%d", time.Counter,
|
||||||
time.Day, time.Month, time.Year,
|
time.Day, time.Month, time.Year,
|
||||||
time.Hour, time.Minute, time.Second);
|
time.Hour, time.Minute, time.Second);
|
||||||
TaskManager->Sleep(200);
|
TaskManager->Sleep(200);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user