Skip to content

Commit cdccee8

Browse files
committed
feat: wasi-0.3.0 draft
Signed-off-by: Bailey Hayes <[email protected]>
1 parent e9ef266 commit cdccee8

File tree

4 files changed

+159
-0
lines changed

4 files changed

+159
-0
lines changed

wit-0.3.0-draft/monotonic-clock.wit

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package wasi:clocks@0.3.0;
2+
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
3+
/// time.
4+
///
5+
/// It is intended to be portable at least between Unix-family platforms and
6+
/// Windows.
7+
///
8+
/// A monotonic clock is a clock which has an unspecified initial value, and
9+
/// successive reads of the clock will produce non-decreasing values.
10+
@since(version = 0.3.0)
11+
interface monotonic-clock {
12+
/// An instant in time, in nanoseconds. An instant is relative to an
13+
/// unspecified initial value, and can only be compared to instances from
14+
/// the same monotonic-clock.
15+
@since(version = 0.3.0)
16+
type instant = u64;
17+
18+
/// A duration of time, in nanoseconds.
19+
@since(version = 0.3.0)
20+
type duration = u64;
21+
22+
/// Read the current value of the clock.
23+
///
24+
/// The clock is monotonic, therefore calling this function repeatedly will
25+
/// produce a sequence of non-decreasing values.
26+
@since(version = 0.3.0)
27+
now: func() -> instant;
28+
29+
/// Query the resolution of the clock. Returns the duration of time
30+
/// corresponding to a clock tick.
31+
@since(version = 0.3.0)
32+
resolution: func() -> duration;
33+
34+
/// Create a `future` which will resolve once the specified instant
35+
/// has occurred.
36+
@since(version = 0.3.0)
37+
subscribe-instant: func(
38+
when: instant,
39+
) -> future;
40+
41+
/// Create a `future` that will resolve after the specified duration has
42+
/// elapsed from the time this function is invoked.
43+
@since(version = 0.3.0)
44+
subscribe-duration: func(
45+
when: duration,
46+
) -> future;
47+
}

wit-0.3.0-draft/timezone.wit

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package wasi:clocks@0.3.0;
2+
3+
@unstable(feature = clocks-timezone)
4+
interface timezone {
5+
@unstable(feature = clocks-timezone)
6+
use wall-clock.{datetime};
7+
8+
/// Return information needed to display the given `datetime`. This includes
9+
/// the UTC offset, the time zone name, and a flag indicating whether
10+
/// daylight saving time is active.
11+
///
12+
/// If the timezone cannot be determined for the given `datetime`, return a
13+
/// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
14+
/// saving time.
15+
@unstable(feature = clocks-timezone)
16+
display: func(when: datetime) -> timezone-display;
17+
18+
/// The same as `display`, but only return the UTC offset.
19+
@unstable(feature = clocks-timezone)
20+
utc-offset: func(when: datetime) -> s32;
21+
22+
/// Information useful for displaying the timezone of a specific `datetime`.
23+
///
24+
/// This information may vary within a single `timezone` to reflect daylight
25+
/// saving time adjustments.
26+
@unstable(feature = clocks-timezone)
27+
record timezone-display {
28+
/// The number of seconds difference between UTC time and the local
29+
/// time of the timezone.
30+
///
31+
/// The returned value will always be less than 86400 which is the
32+
/// number of seconds in a day (24*60*60).
33+
///
34+
/// In implementations that do not expose an actual time zone, this
35+
/// should return 0.
36+
utc-offset: s32,
37+
38+
/// The abbreviated name of the timezone to display to a user. The name
39+
/// `UTC` indicates Coordinated Universal Time. Otherwise, this should
40+
/// reference local standards for the name of the time zone.
41+
///
42+
/// In implementations that do not expose an actual time zone, this
43+
/// should be the string `UTC`.
44+
///
45+
/// In time zones that do not have an applicable name, a formatted
46+
/// representation of the UTC offset may be returned, such as `-04:00`.
47+
name: string,
48+
49+
/// Whether daylight saving time is active.
50+
///
51+
/// In implementations that do not expose an actual time zone, this
52+
/// should return false.
53+
in-daylight-saving-time: bool,
54+
}
55+
}

wit-0.3.0-draft/wall-clock.wit

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package wasi:clocks@0.3.0;
2+
/// WASI Wall Clock is a clock API intended to let users query the current
3+
/// time. The name "wall" makes an analogy to a "clock on the wall", which
4+
/// is not necessarily monotonic as it may be reset.
5+
///
6+
/// It is intended to be portable at least between Unix-family platforms and
7+
/// Windows.
8+
///
9+
/// A wall clock is a clock which measures the date and time according to
10+
/// some external reference.
11+
///
12+
/// External references may be reset, so this clock is not necessarily
13+
/// monotonic, making it unsuitable for measuring elapsed time.
14+
///
15+
/// It is intended for reporting the current date and time for humans.
16+
@since(version = 0.3.0)
17+
interface wall-clock {
18+
/// A time and date in seconds plus nanoseconds.
19+
@since(version = 0.3.0)
20+
record datetime {
21+
seconds: u64,
22+
nanoseconds: u32,
23+
}
24+
25+
/// Read the current value of the clock.
26+
///
27+
/// This clock is not monotonic, therefore calling this function repeatedly
28+
/// will not necessarily produce a sequence of non-decreasing values.
29+
///
30+
/// The returned timestamps represent the number of seconds since
31+
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
32+
/// also known as [Unix Time].
33+
///
34+
/// The nanoseconds field of the output is always less than 1000000000.
35+
///
36+
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
37+
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
38+
@since(version = 0.3.0)
39+
now: func() -> datetime;
40+
41+
/// Query the resolution of the clock.
42+
///
43+
/// The nanoseconds field of the output is always less than 1000000000.
44+
@since(version = 0.3.0)
45+
resolution: func() -> datetime;
46+
}

wit-0.3.0-draft/world.wit

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package wasi:clocks@0.3.0;
2+
3+
@since(version = 0.3.0)
4+
world imports {
5+
@since(version = 0.3.0)
6+
import monotonic-clock;
7+
@since(version = 0.3.0)
8+
import wall-clock;
9+
@unstable(feature = clocks-timezone)
10+
import timezone;
11+
}

0 commit comments

Comments
 (0)