Skip to content

Commit 367ec46

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 f8e73b8 commit 367ec46

File tree

2 files changed

+25
-40
lines changed

2 files changed

+25
-40
lines changed

README.md

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

9494
```rust
9595
let instant: Instant = system_clock::now();
96-
97-
let timezone_display: TimezoneDisplay = timezone::display(instant);
98-
99-
println!("the timezone is {}", timezone_display.id);
96+
let id = timezone::id();
97+
let offset_h = timezone::utc_offset(instant) as f64 / 3600e9;
98+
println!("the timezone is {} at UTC{:+}", id, offset_h);
10099
```
101100

102101
### Detailed design discussion

wit-0.3.0-draft/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)