Skip to content

Commit 205bdc8

Browse files
committed
Refactor timezone-display into separate methods
If the timezone-display ID is an IANA ID, and we are going with the approach of not making the localized ("PST" vs "PDT" vs "PT") name part of this component, then the current time zone doesn't depend on the current time. After removing the isDST flag, timezone-display contains two pieces of data, the ID and the UTC offset. The UTC offset is already available via a function that takes an Instant as input. The ID could just be available via its own function that doesn't take any input. In that case there would be no need for timezone-display.
1 parent b21c4a5 commit 205bdc8

File tree

3 files changed

+40
-75
lines changed

3 files changed

+40
-75
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ default-monotonic-clock: monotonic-clock
8989

9090
```rust
9191
let instant: Instant = system_clock::now();
92-
93-
let timezone_display: TimezoneDisplay = timezone::display(instant);
94-
95-
println!("the timezone is {}", timezone_display.id);
92+
let id = timezone::id();
93+
let offset_h = timezone::utc_offset(instant) as f64 / 3600e9;
94+
println!("the timezone is {} at UTC{:+}", id, offset_h);
9695
```
9796

9897
### Detailed design discussion

imports.md

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -165,51 +165,31 @@ also known as <a href="https://en.wikipedia.org/wiki/Unix_time">Unix Time</a>.</
165165
<h4><a name="instant"></a><code>type instant</code></h4>
166166
<p><a href="#instant"><a href="#instant"><code>instant</code></a></a></p>
167167
<p>
168-
#### <a name="timezone_display"></a>`record timezone-display`
169-
<p>Information useful for displaying a specific <a href="#instant"><code>instant</code></a> in the currently
170-
configured time zone.</p>
171-
<h5>Record Fields</h5>
172-
<ul>
173-
<li>
174-
<p><a name="timezone_display.utc_offset"></a><a href="#utc_offset"><code>utc-offset</code></a>: <code>s64</code></p>
175-
<p>The number of nanoseconds difference between UTC time and the local
176-
time of the timezone.
177-
<p>The returned value will always be less than 86,400,000,000,000 which
178-
is the number of nanoseconds in a day (24<em>60</em>60*1e9).</p>
179-
<p>In implementations that do not expose an actual time zone, this
180-
should return 0.</p>
181-
</li>
182-
<li>
183-
<p><a name="timezone_display.id"></a><code>id</code>: <code>string</code></p>
184-
<p>The IANA identifier of the timezone. The id `UTC` indicates
185-
Coordinated Universal Time. Otherwise, this should be an identifier
186-
from the IANA Time Zone Database.
168+
----
169+
<h3>Functions</h3>
170+
<h4><a name="id"></a><code>id: func</code></h4>
171+
<p>Return the IANA identifier of the currently configured timezone. The id
172+
<code>UTC</code> indicates Coordinated Universal Time. Otherwise, this should be an
173+
identifier from the IANA Time Zone Database.</p>
187174
<p>For displaying to a user, the identifier should be converted into a
188175
localized name by means of an internationalization API.</p>
189176
<p>In implementations that do not expose an actual time zone, this
190177
should be the string <code>UTC</code>.</p>
191178
<p>In time zones that do not have an applicable name, a formatted
192179
representation of the UTC offset may be returned, such as <code>-04:00</code>.</p>
193-
</li>
194-
</ul>
195-
<hr />
196-
<h3>Functions</h3>
197-
<h4><a name="display"></a><code>display: func</code></h4>
198-
<p>Return information needed to display the given <a href="#instant"><code>instant</code></a> in the
199-
currently configured time zone. This includes the UTC offset and the
200-
time zone name.</p>
201-
<p>If the currently configured timezone cannot be determined, return a
202-
<a href="#timezone_display"><code>timezone-display</code></a> for <code>UTC</code> with a <a href="#utc_offset"><code>utc-offset</code></a> of 0.</p>
203-
<h5>Params</h5>
204-
<ul>
205-
<li><a name="display.when"></a><code>when</code>: <a href="#instant"><a href="#instant"><code>instant</code></a></a></li>
206-
</ul>
207180
<h5>Return values</h5>
208181
<ul>
209-
<li><a name="display.0"></a> <a href="#timezone_display"><a href="#timezone_display"><code>timezone-display</code></a></a></li>
182+
<li><a name="id.0"></a> <code>string</code></li>
210183
</ul>
211184
<h4><a name="utc_offset"></a><code>utc-offset: func</code></h4>
212-
<p>The same as <a href="#display"><code>display</code></a>, but only return the UTC offset.</p>
185+
<p>The number of nanoseconds difference between UTC time and the local
186+
time of the currently configured timezone at the exact time of
187+
<a href="#instant"><code>instant</code></a>.</p>
188+
<p>The magnitude of the returned value will always be less than
189+
86,400,000,000,000 which is the number of nanoseconds in a day
190+
(24<em>60</em>60*1e9).</p>
191+
<p>In implementations that do not expose an actual time zone, this
192+
should return 0.</p>
213193
<h5>Params</h5>
214194
<ul>
215195
<li><a name="utc_offset.when"></a><code>when</code>: <a href="#instant"><a href="#instant"><code>instant</code></a></a></li>

wit/timezone.wit

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,31 @@ interface timezone {
55
@unstable(feature = clocks-timezone)
66
use system-clock.{instant};
77

8-
/// Return information needed to display the given `instant` in the
9-
/// currently configured time zone. This includes the UTC offset and the
10-
/// time zone name.
8+
/// Return the IANA identifier of the currently configured timezone. The id
9+
/// `UTC` indicates Coordinated Universal Time. Otherwise, this should be an
10+
/// identifier from the IANA Time Zone Database.
1111
///
12-
/// If the currently configured timezone cannot be determined, return a
13-
/// `timezone-display` for `UTC` with a `utc-offset` of 0.
12+
/// For displaying to a user, the identifier should be converted into a
13+
/// localized name by means of an internationalization API.
14+
///
15+
/// In implementations that do not expose an actual time zone, this
16+
/// should be the string `UTC`.
17+
///
18+
/// In time zones that do not have an applicable name, a formatted
19+
/// representation of the UTC offset may be returned, such as `-04:00`.
1420
@unstable(feature = clocks-timezone)
15-
display: func(when: instant) -> timezone-display;
21+
id: func() -> string;
1622

17-
/// The same as `display`, but only return the UTC offset.
23+
/// The number of nanoseconds difference between UTC time and the local
24+
/// time of the currently configured timezone at the exact time of
25+
/// `instant`.
26+
///
27+
/// The magnitude of the returned value will always be less than
28+
/// 86,400,000,000,000 which is the number of nanoseconds in a day
29+
/// (24*60*60*1e9).
30+
///
31+
/// In implementations that do not expose an actual time zone, this
32+
/// should return 0.
1833
@unstable(feature = clocks-timezone)
1934
utc-offset: func(when: instant) -> s64;
20-
21-
/// Information useful for displaying a specific `instant` in the currently
22-
/// configured time zone.
23-
@unstable(feature = clocks-timezone)
24-
record timezone-display {
25-
/// The number of nanoseconds difference between UTC time and the local
26-
/// time of the timezone.
27-
///
28-
/// The returned value will always be less than 86,400,000,000,000 which
29-
/// is the number of nanoseconds in a day (24*60*60*1e9).
30-
///
31-
/// In implementations that do not expose an actual time zone, this
32-
/// should return 0.
33-
utc-offset: s64,
34-
35-
/// The IANA identifier of the timezone. The id `UTC` indicates
36-
/// Coordinated Universal Time. Otherwise, this should be an identifier
37-
/// from the IANA Time Zone Database.
38-
///
39-
/// For displaying to a user, the identifier should be converted into a
40-
/// localized name by means of an internationalization API.
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-
id: string,
48-
}
4935
}

0 commit comments

Comments
 (0)