time.ha (851B)
1 // License: MPL-2.0 2 // (c) 2021-2022 Byron Torres <b@torresjrjr.com> 3 use errors; 4 use time; 5 6 // Calculates the wall clock (hour, minute, second, nanosecond), 7 // given a time since the start of a day. 8 fn calc_hmsn(t: time::duration) (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 since the start of a day, 18 // given a wall clock (hour, minute, second, nanosecond). 19 fn calc_time__hmsn( 20 hour: int, 21 min: int, 22 sec: int, 23 nsec: int, 24 ) (time::duration | 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 };