Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make timezone a per-instance value #48

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ read the current time and to measure elapsed time.

### Non-goals

WASI Clocks is not aiming to cover timezones, daylight savings time, date
formatting, or modifying the time of a clock.
WASI Clocks is not aiming to cover date formatting, or modifying the time of a clock.

### API walk-through

Expand All @@ -66,13 +65,11 @@ default-monotonic-clock: monotonic-clock
```

```rust
let clock: MonotonicClock = default_monotonic_clock();

let start: Instant = monotonic_clock_now(clock);
let start: Instant = monotonic_clock::now(clock);

// some stuff

let stop: Instant = monotonic_clock_now(clock);
let stop: Instant = monotonic_clock::now(clock);

let elapsed: Instant = stop - start;
```
Expand All @@ -81,13 +78,21 @@ default-monotonic-clock: monotonic-clock
#### Telling the current human time:

```rust
let clock: WallClock = default_wall_clock();

let the_current_time = wall_clock_now();
let the_current_time = wall_clock::now();

println!("it has been {} seconds and {} nanoseconds since the Unix epoch!", the_current_time.seconds, the_current_time.nanoseconds);
```

#### Retrieving the timezone:

```rust
let datetime: Datetime = wall_clock::now();

let timezone_display: TimezoneDisplay = timezone::display(datetime);

println!("the timezone is {}", timezone_display.name);
```

### Detailed design discussion

### What should the type of a timestamp be?
Expand Down
18 changes: 1 addition & 17 deletions example-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ also known as <a href="https://en.wikipedia.org/wiki/Unix_time">Unix Time</a>.</
<p>
#### <a name="timezone_display">`record timezone-display`</a>
<p>Information useful for displaying the timezone of a specific <a href="#datetime"><code>datetime</code></a>.</p>
<p>This information may vary within a single <a href="#timezone"><code>timezone</code></a> to reflect daylight
<p>This information may vary within a single <code>timezone</code> to reflect daylight
saving time adjustments.</p>
<h5>Record Fields</h5>
<ul>
Expand Down Expand Up @@ -179,13 +179,6 @@ representation of the UTC offset may be returned, such as <code>-04:00</code>.</
should return false.</p>
</li>
</ul>
<h4><a name="timezone"><code>type timezone</code></a></h4>
<p><code>u32</code></p>
<p>A timezone.
<p>In timezones that recognize daylight saving time, also known as daylight
time and summer time, the information returned from the functions varies
over time to reflect these adjustments.</p>
<p>This <a href="https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources">represents a resource</a>.</p>
<hr />
<h3>Functions</h3>
<h4><a name="display"><code>display: func</code></a></h4>
Expand All @@ -197,7 +190,6 @@ daylight saving time is active.</p>
saving time.</p>
<h5>Params</h5>
<ul>
<li><a name="display.this"><code>this</code></a>: <a href="#timezone"><a href="#timezone"><code>timezone</code></a></a></li>
<li><a name="display.when"><code>when</code></a>: <a href="#datetime"><a href="#datetime"><code>datetime</code></a></a></li>
</ul>
<h5>Return values</h5>
Expand All @@ -208,17 +200,9 @@ saving time.</p>
<p>The same as <a href="#display"><code>display</code></a>, but only return the UTC offset.</p>
<h5>Params</h5>
<ul>
<li><a name="utc_offset.this"><code>this</code></a>: <a href="#timezone"><a href="#timezone"><code>timezone</code></a></a></li>
<li><a name="utc_offset.when"><code>when</code></a>: <a href="#datetime"><a href="#datetime"><code>datetime</code></a></a></li>
</ul>
<h5>Return values</h5>
<ul>
<li><a name="utc_offset.0"></a> <code>s32</code></li>
</ul>
<h4><a name="drop_timezone"><code>drop-timezone: func</code></a></h4>
<p>Dispose of the specified input-stream, after which it may no longer
be used.</p>
<h5>Params</h5>
<ul>
<li><a name="drop_timezone.this"><code>this</code></a>: <a href="#timezone"><a href="#timezone"><code>timezone</code></a></a></li>
</ul>
17 changes: 2 additions & 15 deletions wit/timezone.wit
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
interface timezone {
use wall-clock.{datetime}

/// A timezone.
///
/// In timezones that recognize daylight saving time, also known as daylight
/// time and summer time, the information returned from the functions varies
/// over time to reflect these adjustments.
///
/// This [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources).
type timezone = u32

/// Return information needed to display the given `datetime`. This includes
/// the UTC offset, the time zone name, and a flag indicating whether
/// daylight saving time is active.
///
/// If the timezone cannot be determined for the given `datetime`, return a
/// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
/// saving time.
display: func(this: timezone, when: datetime) -> timezone-display
display: func(when: datetime) -> timezone-display

/// The same as `display`, but only return the UTC offset.
utc-offset: func(this: timezone, when: datetime) -> s32

/// Dispose of the specified input-stream, after which it may no longer
/// be used.
drop-timezone: func(this: timezone)
utc-offset: func(when: datetime) -> s32

/// Information useful for displaying the timezone of a specific `datetime`.
///
Expand Down