From 205bdc8c73e7bdda25dd1bd4b703a1680e47acd1 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 11 Jul 2024 11:42:09 -0700 Subject: [PATCH] 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. --- README.md | 7 +++--- imports.md | 50 +++++++++++++---------------------------- wit/timezone.wit | 58 ++++++++++++++++++------------------------------ 3 files changed, 40 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 8af2de6..e1018be 100644 --- a/README.md +++ b/README.md @@ -89,10 +89,9 @@ default-monotonic-clock: monotonic-clock ```rust let instant: Instant = system_clock::now(); - - let timezone_display: TimezoneDisplay = timezone::display(instant); - - println!("the timezone is {}", timezone_display.id); + let id = timezone::id(); + let offset_h = timezone::utc_offset(instant) as f64 / 3600e9; + println!("the timezone is {} at UTC{:+}", id, offset_h); ``` ### Detailed design discussion diff --git a/imports.md b/imports.md index c181109..a96f702 100644 --- a/imports.md +++ b/imports.md @@ -165,51 +165,31 @@ also known as Unix Time.type instant

instant

-#### `record timezone-display` -

Information useful for displaying a specific instant in the currently -configured time zone.

-
Record Fields
- -
-

Functions

-

display: func

-

Return information needed to display the given instant in the -currently configured time zone. This includes the UTC offset and the -time zone name.

-

If the currently configured timezone cannot be determined, return a -timezone-display for UTC with a utc-offset of 0.

-
Params
-
Return values

utc-offset: func

-

The same as display, but only return the UTC offset.

+

The number of nanoseconds difference between UTC time and the local +time of the currently configured timezone at the exact time of +instant.

+

The magnitude of the returned value will always be less than +86,400,000,000,000 which is the number of nanoseconds in a day +(246060*1e9).

+

In implementations that do not expose an actual time zone, this +should return 0.

Params