mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:17:35 +00:00
AK: Add Time::from_ticks()
This helper allows Time to be constructed from a tick count and a ticks per second value.
This commit is contained in:
parent
5238e38886
commit
39bfc48ea7
2 changed files with 10 additions and 0 deletions
|
@ -38,6 +38,15 @@ unsigned day_of_week(int year, unsigned month, int day)
|
||||||
return (year + year / 4 - year / 100 + year / 400 + seek_table[month - 1] + day) % 7;
|
return (year + year / 4 - year / 100 + year / 400 + seek_table[month - 1] + day) % 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Time Time::from_ticks(clock_t ticks, time_t ticks_per_second)
|
||||||
|
{
|
||||||
|
auto secs = ticks % ticks_per_second;
|
||||||
|
|
||||||
|
i32 nsecs = 1'000'000'000 * (ticks - (ticks_per_second * secs)) / ticks_per_second;
|
||||||
|
i32 extra_secs = sane_mod(nsecs, 1'000'000'000);
|
||||||
|
return Time::from_half_sanitized(secs, extra_secs, nsecs);
|
||||||
|
}
|
||||||
|
|
||||||
Time Time::from_timespec(const struct timespec& ts)
|
Time Time::from_timespec(const struct timespec& ts)
|
||||||
{
|
{
|
||||||
i32 nsecs = ts.tv_nsec;
|
i32 nsecs = ts.tv_nsec;
|
||||||
|
|
|
@ -187,6 +187,7 @@ public:
|
||||||
i64 seconds = sane_mod(milliseconds, 1'000);
|
i64 seconds = sane_mod(milliseconds, 1'000);
|
||||||
return Time(seconds, milliseconds * 1'000'000);
|
return Time(seconds, milliseconds * 1'000'000);
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] static Time from_ticks(clock_t, time_t);
|
||||||
[[nodiscard]] static Time from_timespec(const struct timespec&);
|
[[nodiscard]] static Time from_timespec(const struct timespec&);
|
||||||
[[nodiscard]] static Time from_timeval(const struct timeval&);
|
[[nodiscard]] static Time from_timeval(const struct timeval&);
|
||||||
// We don't pull in <stdint.h> for the pretty min/max definitions because this file is also included in the Kernel
|
// We don't pull in <stdint.h> for the pretty min/max definitions because this file is also included in the Kernel
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue