-
Notifications
You must be signed in to change notification settings - Fork 176
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
Class hierarchy for DateTimeFormat (incl. runtime toggle switches) #380
Comments
I am not sure I understand all the consequences, but I support the idea of giving the choice to authors. DateTimePatterns may answer the question of ordering the "Parts" (in the sense of FormatToParts) in the right order with respect to the language and region, and keeping consistency while displaying elements e.g. "/" if date if |
I think there is some good functionality here, but not in the use case described. But now I think I do... I think this is good to have / needed when the result depends on the input data, but not otherwise. If I want to show a 12h time in one area, and a 24h time in another, I need 2 formatters. And that's OK. We have good use cases, some of them implemented and working:
So I would summarize this as:
BUT: I changed my mind, and now I want other fields / hour style is not a valid use case. So based on this kind of "rules of thumb" I think that from the initial entry the use case 1 and 2 are not valid, but 3 is. |
Agreed about 12h/24h time. In the OP, I was conflating two related but separate problems: you should always have data for both the 12h and the 24h forms, but you only need one of them at a time in the formatter object.
I agree with this, and my pointers to tc39/ecma402#426 and tc39/ecma402#508 (use case 3) are examples of where the pattern does depend on the input data. All I'm proposing in this thread is to generalize the problem of "pick pattern based on input data" by separating the public DateTimeFormat[ter] API from the DateTimePattern API. In some cases, DateTimeFormat[ter] might unconditionally use only one DateTimePattern, but in other cases, it might have a set of DateTimePatterns that it delegates to. That solves case 3, but it could also be extended in userland to solve cases 1 and 2. |
Other than "have a set of DateTimePatterns that it delegates to", LGTM. It might be just lingo. But I would not "delegate to" a pattern. So "DateTimeFormat ... has a set of DateTimePatterns, and selects which one to use based on input" ? |
Call it a DateTimeSingleFormat instead of a DateTimePattern, then. DateTimeFormat wraps a list of one or more DateTimeSingleFormats, and delegates to one of them. I'm proposing one class that formats a datetime according to a pattern, and another class that figures out which one to use. |
I would like to broaden the scope of this issue a bit to cover the overall class hierarchy of DateTimeFormat. Here are specific pieces of DateTimeFormat which I would like to see spun off:
The higher-level type DateTimeFormat should look largely the same, but having these separate pieces will make it easier to reason about the code and the modularity of the individual pieces. They may also be useful to allow FFI to have the same level of modularity. |
I'd like to bring this up for discussion again now that we've been making progress on skeletons and time zones. Here's what I see as actionable:
|
In #598, @nordzilla introduced a standalone component TimeZoneFormat, and a new type ZonedDateTimeFormat that wraps the pair of DateTimeFormat with TimeZoneFormat. I agree with this approach. Consider renaming DateTimeFormat to PlainDateTimeFormat for better parallelism with Temporal. |
@gregtatum interested in the design work. Implementation may be done by someone else. @zbraniecki to assist in some ways. |
Design work is done, see #1317 for the plan. |
The Ideal Components Bag is an important part of the class hierarchy, but the class hierarchy also includes how we reason about the modularity of time zones, calendars, etc. I'm going to move this issue to the 1.0 milestone. |
At a very basic level, I think we should split DateTimeFormat as follows:
Internally, we will likely want additional classes to do things like skeleton resolution. This does not need to be public API. An argument could be made that DateTimePatternInterpolator should be internal as well. |
In terms of 1.0:
@dminor is tentatively interested in this. |
This is a first step towards fixing unicode-org#380.
This is a first step towards fixing unicode-org#380.
This is a first step towards fixing unicode-org#380.
* Split date and time data keys. This is a first step towards fixing #380. * Revert accidental change to work_log.rs * Update readme * Address review feedback
Partial fix for unicode-org#380
Right now, DateTimeFormat uses a model where a single pattern is prepped when the object is constructed. This is in line with ICU4C SimpleDateFormat. However, I think we should move away from that model.
In addition to being good i18n practice, ECMA-402 is also pushing us in this direction. Here are three reasons why DateTimeFormat, or at least the data backing up DateTimeFormat, may need to carry multiple patterns at once:
Specific thoughts:
utils/
namespace.Thoughts?
CC @zbraniecki
The text was updated successfully, but these errors were encountered: