Skip to content

Commit 0ea0f2e

Browse files
committed
Add timezone host functions.
1 parent 1512a95 commit 0ea0f2e

File tree

25 files changed

+300
-19
lines changed

25 files changed

+300
-19
lines changed

Cargo.lock

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ humantime = "2.0.0"
319319
postcard = { version = "1.0.8", default-features = false, features = ['alloc'] }
320320
criterion = { version = "0.5.0", default-features = false, features = ["html_reports", "rayon"] }
321321
rustc-hash = "1.1.0"
322+
chrono = "0.4.26"
323+
chrono-tz = "0.8.3"
322324

323325
# =============================================================================
324326
#

crates/wasi-http/wit/deps/cli/imports.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package wasi:cli@0.2.0;
22

33
world imports {
4-
include wasi:clocks/imports@0.2.0;
4+
include wasi:clocks/imports@0.2.1;
55
include wasi:filesystem/imports@0.2.0;
66
include wasi:sockets/imports@0.2.0;
77
include wasi:random/imports@0.2.0;

crates/wasi-http/wit/deps/clocks/monotonic-clock.wit

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

crates/wasi-http/wit/deps/clocks/wall-clock.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package wasi:clocks@0.2.0;
1+
package wasi:clocks@0.2.1;
22
/// WASI Wall Clock is a clock API intended to let users query the current
33
/// time. The name "wall" makes an analogy to a "clock on the wall", which
44
/// is not necessarily monotonic as it may be reset.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package wasi:clocks@0.2.0;
1+
package wasi:clocks@0.2.1;
22

33
world imports {
44
import monotonic-clock;
55
import wall-clock;
6+
import timezone;
67
}

crates/wasi-http/wit/deps/filesystem/types.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package wasi:[email protected];
2525
/// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
2626
interface types {
2727
use wasi:io/streams@0.2.0.{input-stream, output-stream, error};
28-
use wasi:clocks/wall-clock@0.2.0.{datetime};
28+
use wasi:clocks/wall-clock@0.2.1.{datetime};
2929

3030
/// File size or length of a region within a file.
3131
type filesize = u64;

crates/wasi-http/wit/deps/http/proxy.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package wasi:[email protected];
66
/// outgoing HTTP requests.
77
world proxy {
88
/// HTTP proxies have access to time and randomness.
9-
include wasi:clocks/imports@0.2.0;
9+
include wasi:clocks/imports@0.2.1;
1010
import wasi:random/random@0.2.0;
1111

1212
/// Proxies have standard output and error streams which are expected to

crates/wasi-http/wit/deps/http/types.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// HTTP Requests and Responses, both incoming and outgoing, as well as
33
/// their headers, trailers, and bodies.
44
interface types {
5-
use wasi:clocks/monotonic-clock@0.2.0.{duration};
5+
use wasi:clocks/monotonic-clock@0.2.1.{duration};
66
use wasi:io/streams@0.2.0.{input-stream, output-stream};
77
use wasi:io/error@0.2.0.{error as io-error};
88
use wasi:io/poll@0.2.0.{pollable};

0 commit comments

Comments
 (0)