| 1 |
// SPDX-License-Identifier: MPL-2.0 |
| 2 |
// (c) Hare authors <https://harelang.org> |
| 3 |
|
| 4 |
use time; |
| 5 |
|
| 6 |
// Calculates the wall clock (hour, minute, second, nanosecond), |
| 7 |
// given a time-of-day (amount of daytime progressed in a day). |
| 8 |
fn calc_hmsn(t: i64) (int, int, int, int) = { |
| 9 |
const hour = (t / time::HOUR): int; |
| 10 |
const min = ((t / time::MINUTE) % 60): int; |
| 11 |
const sec = ((t / time::SECOND) % 60): int; |
| 12 |
const nsec = (t % time::SECOND): int; |
| 13 |
return (hour, min, sec, nsec); |
| 14 |
}; |
| 15 |
|
| 16 |
// Calculates the time-of-day (amount of daytime progressed in a day), |
| 17 |
// given a wall clock (hour, minute, second, nanosecond). |
| 18 |
fn calc_daytime__hmsn( |
| 19 |
hour: int, |
| 20 |
min: int, |
| 21 |
sec: int, |
| 22 |
nsec: int, |
| 23 |
) (i64 | invalid) = { // TODO: reconsider `invalid` here |
| 24 |
const t = ( |
| 25 |
(hour * time::HOUR) + |
| 26 |
(min * time::MINUTE) + |
| 27 |
(sec * time::SECOND) + |
| 28 |
(nsec * time::NANOSECOND) |
| 29 |
); |
| 30 |
return t; |
| 31 |
}; |