hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

types.ha (1581B)


      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 // TODO: change the following to defs when compileable.
     29 // https://git.sr.ht/~sircmpwn/harec/tree/211b99a/item/src/typedef.c#L169
     30 
     31 // The earliest representable [[instant]].
     32 export const INSTANT_MIN = instant {
     33 	sec = types::I64_MIN,
     34 	nsec = 0,
     35 };
     36 
     37 // The latest representable [[instant]].
     38 export const INSTANT_MAX = instant {
     39 	sec = types::I64_MAX,
     40 	nsec = SECOND - 1,
     41 };
     42 
     43 // Represents a specific instant in time as seconds (+nanoseconds) since an
     44 // arbitrary epoch. Instants may only be meaningfully compared with other
     45 // instants sourced from the same [[clock]], or handled by the same
     46 // [[time::chrono::timescale]]
     47 export type instant = struct {
     48 	sec: i64,
     49 	nsec: i64,
     50 };
     51 
     52 // Represents a unique interval of time between two [[instant]]s.
     53 export type interval = (instant, instant);