daytime.ha (875B)
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 // TODO: Special case for leap seconds, 61st second? 10 const hour = (t / time::HOUR): int; 11 const min = ((t / time::MINUTE) % 60): int; 12 const sec = ((t / time::SECOND) % 60): int; 13 const nsec = (t % time::SECOND): int; 14 return (hour, min, sec, nsec); 15 }; 16 17 // Calculates the time-of-day (amount of daytime progressed in a day), 18 // given a wall clock (hour, minute, second, nanosecond). 19 fn calc_daytime__hmsn( 20 hour: int, 21 min: int, 22 sec: int, 23 nsec: int, 24 ) (i64 | invalid) = { 25 const t = ( 26 (hour * time::HOUR) + 27 (min * time::MINUTE) + 28 (sec * time::SECOND) + 29 (nsec * time::NANOSECOND) 30 ); 31 return t; 32 };