-
Notifications
You must be signed in to change notification settings - Fork 108
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
Intl.DurationFormat #47
Comments
Brainstorming... Follow an API variation that is more parallel with DateTimeFormat for picking different field lengths: var f = Intl.DurationFormat(locales, {
hour: 'numeric',
minute: '2-digit'
});
f.format(i); // 8:01 |
CLDR provides data for three combinations:
From those skeletons, the default length can be extracted. For example, |
Heads up, this has been advanced to Stage 0 as of today. |
@srl295 - We will need Alternatively, we could just encode a single pattern, like |
This proposal has been advanced to Stage 1 as of today. |
@zbaniecki see http://apps.icu-project.org/icu4jweb/flexTest.jsp?pat=HmsSS&_=en_US and in Polish so the data / algo is there, let me know if this helps |
thanks! Where is this skeleton in CLDR? |
@srl295 - So I assume that flexTest indicates that it's something around the algo to get from skeleton to pattern using this: http://www.unicode.org/cldr/charts/29/summary/en.html#1746 - but I don't see anything on |
@zbraniecki two problems:
Filed a CLDR bug here http://unicode.org/cldr/trac/ticket/9352 |
@srl295, as you pointed out earlier, CLDR/ICU has support for measure format that can be used for duration format. Then, the thread moved to talk about skeletons for DateTime format. The input to DateTime format is 'time' while the input for duration format is 'time delta'. Can skeletons/patterns for the DateTime format be used for measure format? |
@jungshik - I don't see measure format skeletons useful for duration format. Also, CLDR bug for fractional seconds has been assigned to target CLDR 30 which should unblock us here. (http://unicode.org/cldr/trac/ticket/9352) |
Are there plans to support |
@icambron all new formatters will have format and formatToParts :) |
A duplicate issue was opened at #322; see some additional discussion there. |
A first-class Duration object is being added in Temporal. This ECMA-402 proposal for duration formatting needs to be prioritized. |
Possible suggestion: since we are generally moving in the direction of overloading Intl constructor functionality that share similar options, I am wondering if this would be appropriate as a new method on Intl.DateTimeFormat, similar to Intl.DateTimeFormat.prototype.formatRange (CC @fabalbon). For example, const duration = new Temporal.Duration(...);
const fmt = new Intl.DateTimeFormat("en-US", {
minute: "2-digit",
second: "2-digit",
fractionalSecondDigits: 3
});
console.log(fmt.formatDuration(duration));
// "01:23.456" |
Update: @younies is the champion for this proposal, and will be proposing it for Stage 1 at the February TC39 meeting. The proposal repo for all further discussion is here: |
Since there's little progress with deciding on what to do with durations, and ICU's API doesn't seem too defined about it, I'd like to start a discussion about possible choices. It seems to me that we have four:
The common use cases are:
The formatting differs from time formatter, because the UI will define the range of units to be displayed, like
h:m:s
,m:s.S
and the number of digits per unit (m:ss
vsmm:ss
ormm:ss.SSS
vsmm:ss.SS
)NumberFormat
would be convenient for that reason - it would benefit from similar API of definingminimumIntegerDigits
andmaximumIntegerDigits
for each component, and the value itself may be just a number of milliseconds.Fitting it into
UnitFormat
seems to be natural fit for CLDR Unit Elements [0] together withcompound units
,unit sequences
andcoordinate units
, but may be hard and requiring us to bend over backward to accommodate for the options that will be required.Custom
DurationFormat
seems to be the easiest choice from the API design perspective, but it increases the number of objects we specify. It's been the choice I made so far for Firefox OS patterns, but I'll be happy to migrate our code once we reach a consensus here.RuleBasedNumberFormat
is what ICU seems to be using now for duration patterns, but it's a pretty big API most similar to Mozilla's proprietaryDate.prototype.toLocaleFormat
and I'm not sure if we want to go there.The API I use in
DurationFormat
looks like this:Thougths?
[0] http://www.unicode.org/reports/tr35/tr35-general.html#Unit_Elements
The text was updated successfully, but these errors were encountered: