Updating time duration functions.

This commit is contained in:
Christoffer Lerno
2023-09-05 10:57:50 +02:00
parent 53598b8c40
commit ffb7935e12
10 changed files with 80 additions and 60 deletions

View File

@@ -0,0 +1,22 @@
module libc;
import std::time;
/**
* @require self >= 0
**/
fn TimeSpec NanoDuration.to_timespec(self) @inline
{
CLong ns = (CLong)(self % 1000_000_000);
Time_t sec = (Time_t)(self / 1000_000_000);
return { .s = sec, .ns = ns };
}
/**
* @require self >= 0
**/
fn TimeSpec Duration.to_timespec(self) @inline
{
CLong ns = (CLong)(1000 * (self % time::SEC));
Time_t sec = (Time_t)(self / time::SEC);
return { .s = sec, .ns = ns };
}