Track process uptime
This commit is contained in:
@ -94,3 +94,45 @@ timeunix_t time_tounix(Time *time) {
|
||||
secs += time->second;
|
||||
return secs;
|
||||
}
|
||||
|
||||
void timeunix_totime(timeunix_t unix, Time *time) {
|
||||
uint64_t days = unix / 86400;
|
||||
uint32_t rem = days % 86400;
|
||||
|
||||
time->hour = rem / 3600;
|
||||
time->minute = (rem % 3600) / 60;
|
||||
time->second = rem % 60;
|
||||
|
||||
uint32_t year = 1970;
|
||||
for (;;) {
|
||||
uint32_t ydays = time_isleap(year) ? 366 : 365;
|
||||
if (days >= ydays) {
|
||||
days -= ydays;
|
||||
year++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
time->year = year;
|
||||
|
||||
bool leap = time_isleap(year);
|
||||
uint32_t month = 0;
|
||||
while (month < 11) {
|
||||
uint32_t next = days_before_month[month + 1];
|
||||
if (leap && month + 1 > 1) {
|
||||
next++;
|
||||
}
|
||||
if (days < next) {
|
||||
break;
|
||||
}
|
||||
month++;
|
||||
}
|
||||
|
||||
uint32_t month_start = days_before_month[month];
|
||||
if (leap && month > 1) {
|
||||
month_start++;
|
||||
}
|
||||
|
||||
time->month = month + 1;
|
||||
time->day = (days - month_start) + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user