types.ha (1446B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use types; 5 6 // The elapsed time between two instants, in nanoseconds. The largest 7 // representable duration is about 290 years. 8 export type duration = i64; 9 10 // [[duration]] representing a single nanosecond. 11 export def NANOSECOND: duration = 1; 12 13 // [[duration]] representing a single microsecond. 14 export def MICROSECOND: duration = 1000 * NANOSECOND; 15 16 // [[duration]] representing a single millisecond. 17 export def MILLISECOND: duration = 1000 * MICROSECOND; 18 19 // [[duration]] representing a second. 20 export def SECOND: duration = 1000 * MILLISECOND; 21 22 // [[duration]] representing a minute. 23 export def MINUTE: duration = 60 * SECOND; 24 25 // [[duration]] representing an hour. 26 export def HOUR: duration = 60 * MINUTE; 27 28 // The earliest representable [[instant]]. 29 export def INSTANT_MIN = instant { 30 sec = types::I64_MIN, 31 nsec = 0, 32 }; 33 34 // The latest representable [[instant]]. 35 export def INSTANT_MAX = instant { 36 sec = types::I64_MAX, 37 nsec = SECOND - 1, 38 }; 39 40 // Represents a specific instant in time as seconds (+nanoseconds) since an 41 // arbitrary epoch. Instants may only be meaningfully compared with other 42 // instants sourced from the same [[clock]], or handled by the same 43 // [[time::chrono::timescale]] 44 export type instant = struct { 45 sec: i64, 46 nsec: i64, 47 }; 48 49 // Represents a unique interval of time between two [[instant]]s. 50 export type interval = (instant, instant);