Skip to content

Commit

Permalink
Make timezone a per-instance value.
Browse files Browse the repository at this point in the history
Timezone and clock should be handled similarly. If clocks are switched
back to resources, then timezones could be switched back as well.
  • Loading branch information
cdmurph32 committed Aug 23, 2023
1 parent f225090 commit 3c1cadf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 43 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ default-monotonic-clock: monotonic-clock

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

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

println!("the timezone is {}", timezone_display.name);
```
Expand Down
24 changes: 1 addition & 23 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,21 +179,8 @@ 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="instance_timezone"><code>instance-timezone: func</code></a></h4>
<p>Return the system timezone, creating the resource.</p>
<h5>Return values</h5>
<ul>
<li><a name="instance_timezone.0"></a> <a href="#timezone"><a href="#timezone"><code>timezone</code></a></a></li>
</ul>
<h4><a name="display"><code>display: func</code></a></h4>
<p>Return information needed to display the given <a href="#datetime"><code>datetime</code></a>. This includes
the UTC offset, the time zone name, and a flag indicating whether
Expand All @@ -203,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 @@ -214,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>
20 changes: 2 additions & 18 deletions wit/timezone.wit
Original file line number Diff line number Diff line change
@@ -1,33 +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 the system timezone, creating the resource.
instance-timezone: func() -> timezone

/// 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

0 comments on commit 3c1cadf

Please sign in to comment.