-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Well-defined timezone handling #25
Comments
Time zone is interesting because it is orthogonal to locale and can have a "contextual" value (i.e. a default present in the runtime) as well as a need for developers to control it for a given For example, my host might be running in UTC. I might be formatting a message for a customer in
To get the right results, I would expect to be able to control the timezone externally on the formatter. To use a Java example:
However... this seems like an implementation detail or feature. The core question is whether we should require implementations to do anything? I can't think of anything in the core syntax that requires changing here. |
I think datetimes formatting are like units. You really want to format an
element that consists of two parts: the date and the timezone.
…On Wed, Jun 28, 2023 at 2:03 PM Addison Phillips ***@***.***> wrote:
Time zone is interesting because it is orthogonal to locale and can have a
"contextual" value (i.e. a default present in the runtime) as well as a
need for developers to control it for a given MessageFormat instance.
For example, my host might be running in UTC. I might be formatting a
message for a customer in America/Los_Angeles. My pattern is something
like:
{Your order was processed on {$date :date skeleton=EyMd} at {$date :date skeleton=jm}}
To get the right results, I would expect to be able to control the
timezone externally on the formatter. To use a Java example:
MessageFormatter fmt = MessageFormatter.builder(pattern)
.setLocale(customerLocale)
.setTimeZone(customerTZ)
.build();
However... this seems like an implementation detail or feature. The core
question is whether we should *require* implementations to do anything? I
can't think of anything in the core syntax that requires changing here.
—
Reply to this email directly, view it on GitHub
<#25 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJLEMELKCI5V7T3WTGBNZTXNSL3RANCNFSM4KNZUGWA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
@macchiati noted:
I agree and modern Temporal data types help encapsulate this. That said, there are a variety of use cases in which the caller needs or wants to specify a specific time zone (or conversely wants a floating time presentation of a value that appears to have a time zone). Supporting these use cases requires some ability to pass in the desired time zone. Some work on this is being documented in updates to the W3C time zone document, such as here: https://w3c.github.io/timezone/#serializations (shoutout to CJ Butenhoff and Abhijeet Kumar among others who did a lot of research on this). The ability to float and unfloat times and to convert or apply time zones to a given incremental time value is important in getting consistently the desired results. One way to handle one part of this might be by providing
What I don't see is a need for specific syntactical changes to the ABNF related to time zone. The registry entry for |
Closing resolve-candidates per discussion in 2023-07-24 call |
This thread is a spin-off from the requirements gathering (issue #3) about the way timezone is handled in formatting a date/time value.
Original description:
@grhoten commented:
The date/calendar object being formatted could carry timezone information, in which case the formatter can simply print the value in that timezone. However, in many cases the original value is normalized in UTC or otherwise missing timezone information, so the formatter must figure out the timezone to print the value in.
Typically, a calendar object uses a field based internal data structure which contains a timezone field, while a date object uses a simple incremental millisecond count since the Unix time epoch in UTC. The latter type is often chosen as the only native datatype for date/time in modern programming environments as it is easier to evaluate and meets a great majority of the needs of the applications.
Requiring the application to convert a date to a calendar just for presentation in the desired timezone is undesirable. As a matter of fact, modern programming environments support implicit conversion today for basic application scenarios such as printing the current date/time or a timestamp in the user's local time. Applications don't have to specify the presentation timezone, because a 'default timezone is automatically applied for you. For instance, in a browser, the default timezone is the local time where it is running, and
new Date().toString()
would print the current date and time in the local timezone.The desired default timezone is often the local timezone of the end user, but there are many exceptions; for instance, on a mobile device, the desired default may not be the timezone of the user's physical location. Instead, it may be that of the user's "home" location.
Here is a summary of different patterns to apply a timezone in formatting a date/time value:
The syntax should use reasonable defaults and support options that enable the message author to specify how timezone should be applied.
=== Examples for Each Pattern ===
Pattern 1, timezone independent scenario: Most date values that represent a specific day are timezone independent. So date values should be printed in a timezone neutral way by default. If time portion was supplied, it should be ignored.
To print a date of birth, the message template may look similar to the following (The markup is for illustration of the concept only. 'dob' is the parameter name, 'date' is the type.):
DOB: {dob, date}
Let's consider a sample output 'DOB: January 29, 2020' in US locale. The argument set to
dob
may be in several different forms. Here are how the argument value(s) may look like:Pattern 2, default timezone scenario: This pattern is for compatibility with the platform defaults so the behavior would vary depending on the platform's implementation. I feel this pattern does not have to be supported as long as the other patterns are supported. I am still including this as a pattern because it helps understand the differences from the other patterns and why using a platform default could cause problems.
In particular, because of the dependency on the platform's default implementation, the application behavior may be unpredictable or require a specific configuration to make the behavior predictable.
To print a date of birth using the platform's default timezone, the message template may look similar to the following (The markup is for illustration of the concept only. 'dob' is the parameter name, 'date' is the type, 'platform' is for selecting this option.):
DOB: {dob, date, platform}
Let's consider a sample output 'DOB: January 29, 2020' in US locale. The argument set to
dob
may be in several different forms. Here are how the argument value(s) may look like:Pattern 3, user's preferred/home timezone: A timestamp value that represents a specific moment is typically to be converted to a presentation timezone, which is normally the timezone of the user's home location. So timestamp values should be printed with timezone convertion applied by default. If timezone was not set, a default may be used.
To print when an object is last updated, the message template may look similar to the following (The markup is for illustration of the concept only. 'instant' is the parameter name, 'datetime' is the type, 'user' selects this option.):
Last updated: {instant, datetime, user}
Let's consider a sample output 'Last updated: January 29, 2020 05:20:30 PM' in US locale where the user's preferred locale is US Pacific time (behind 8 hours from UTC). The argument set to
instant
may be in several different forms. Here are how the argument value(s) may look like:Pattern 4, business entity timezone: A timestamp value that represents a specific moment may be converted for presentation to a timezone associated with a business entity.
When printing the time of intraday stock prices, the stock exchange is the business entity and the timezone of its location would be the relevant business entity timezone in which the timestamps should be presented. In this case, the message template may look similar to the following (The markup is for illustration of the concept only. 'time' is the parameter name, 'datetime' is the type, 'tz' may be the name of a function that supplies the timezone of the stock market, 'price' is where the stock price would go.):
{time, datetime, tz} {price}
Let's consider a sample output 'January 29, 2020 12:00:00 PM $234.56' in US locale in the timezone of the stock market. The argument set to
time
may be in several different forms. Here are how the argument value(s) may look like:Pattern 5, Hardcoding scenarios: A spcific timezone may be explicitly set on the message when it is appropriate to do so. This may be the case when the timezone for presentation is known when composing the message.
To print intraday stock prices in an application for NYSE, it may be fine to hardcode the US Eastern timezone. Then the message template may look similar to the following (The markup is for illustration of the concept only. 'time' is the parameter name, 'datetime' is the type, 'America/New_York' is the presentation timezone, 'price' is where the stock price would go.):
{time, datetime, 'America/New_York'} {price}
Let's consider a sample output 'January 29, 2020 12:00:00 PM $234.56' in US locale in US Eastern time. The argument set to
time
may be in several different forms. Here are how the argument value(s) may look like:=== Summary ===
Well-defined timezone handling enables the message author to control the presentation timezone to achieve the intended application behavior, by making the timezone conversion behavior predictable. The set of arguments the application needs to supply at runtime is clearly defined and a strict coding pattern is enforced to reduce the chance to encounter an unexpected result. Correct coding patterns to acheive desired application behaviors are promoted through syntax checking of the message, linting of the application and good documentation.
This is opposite from what is typically happening today: Currently, the way application code is written largely defines the presentation behavior so it is hard for the message author to tell if the message will be printed in the intended timezone. It is the application developer who is responsible for writing the correct code that performs the intended timezone conversion. With well-defined timezone handling, application developers would no longer play the primary role, because the message itself describes how timezone conversion is to happen.
The text was updated successfully, but these errors were encountered: