Fixed time.precise_clock

This commit is contained in:
Jeroen van Rijn
2024-08-10 12:35:58 +02:00
parent be7a1f671c
commit d267735d99

View File

@@ -344,11 +344,32 @@ Obtain the time components from a time, a duration or a stopwatch's total.
*/
clock :: proc { clock_from_time, clock_from_duration, clock_from_stopwatch }
/*
Obtain the time components from a time, a duration or a stopwatch's total, including nanoseconds.
*/
precise_clock :: proc { precise_clock_from_time, precise_clock_from_duration, precise_clock_from_stopwatch }
/*
Obtain the time components from a time.
*/
clock_from_time :: proc "contextless" (t: Time) -> (hour, min, sec: int) {
return clock_from_seconds(_time_abs(t))
hour, min, sec, _ = precise_clock_from_time(t)
return
}
/*
Obtain the time components from a time, including nanoseconds.
*/
precise_clock_from_time :: proc "contextless" (t: Time) -> (hour, min, sec, nanos: int) {
// Time in nanoseconds since 1-1-1970 00:00
sec, nanos = int(t._nsec) / 1e9, int(t._nsec) % 1e9
sec += int(INTERNAL_TO_ABSOLUTE)
sec = sec % SECONDS_PER_DAY
hour = sec / SECONDS_PER_HOUR
sec -= hour * SECONDS_PER_HOUR
min = sec / SECONDS_PER_MINUTE
sec -= min * SECONDS_PER_MINUTE
return
}
/*
@@ -358,6 +379,13 @@ clock_from_duration :: proc "contextless" (d: Duration) -> (hour, min, sec: int)
return clock_from_seconds(u64(d/1e9))
}
/*
Obtain the time components from a duration, including nanoseconds.
*/
precise_clock_from_duration :: proc "contextless" (d: Duration) -> (hour, min, sec, nanos: int) {
return precise_clock_from_time({_nsec=i64(d)})
}
/*
Obtain the time components from a stopwatch's total.
*/
@@ -365,11 +393,18 @@ clock_from_stopwatch :: proc "contextless" (s: Stopwatch) -> (hour, min, sec: in
return clock_from_duration(stopwatch_duration(s))
}
/*
Obtain the time components from a stopwatch's total, including nanoseconds
*/
precise_clock_from_stopwatch :: proc "contextless" (s: Stopwatch) -> (hour, min, sec, nanos: int) {
return precise_clock_from_duration(stopwatch_duration(s))
}
/*
Obtain the time components from the number of seconds.
*/
clock_from_seconds :: proc "contextless" (nsec: u64) -> (hour, min, sec: int) {
sec = int(nsec % SECONDS_PER_DAY)
clock_from_seconds :: proc "contextless" (in_sec: u64) -> (hour, min, sec: int) {
sec = int(in_sec % SECONDS_PER_DAY)
hour = sec / SECONDS_PER_HOUR
sec -= hour * SECONDS_PER_HOUR
min = sec / SECONDS_PER_MINUTE