Skip to content
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

Add unanchored intervals #322

Closed
ByteEater-pl opened this issue Feb 13, 2019 · 6 comments
Closed

Add unanchored intervals #322

ByteEater-pl opened this issue Feb 13, 2019 · 6 comments

Comments

@ByteEater-pl
Copy link

The IntervalFormat issue postulates an API for creating strings like "3—5 May 2022". There's also a proposal for instances specified relatively, e.g. "two years and five days ago", "in 1 hour, 2 minutes and 1 second". There's a simpler and also commonly needed case that's missing: just "2 days", "two years and five days", "1 hour, 2 minutes and 1 second" (no "ago" or "in").

@sffc
Copy link
Contributor

sffc commented Feb 13, 2019

The IntervalFormat issue postulates an API for creating strings like "3—5 May 2022". There's also a proposal for instances specified relatively, e.g. "two years and five days ago", "in 1 hour, 2 minutes and 1 second".

This is actually implemented in a different Stage 3 proposal:

https://github.com/tc39/proposal-intl-relative-time

There's a simpler and also commonly needed case that's missing: just "2 days", "two years and five days", "1 hour, 2 minutes and 1 second" (no "ago" or "in").

This is covered by unit formatting:

https://github.com/tc39/proposal-unified-intl-numberformat

When combining multiple such units, you can use Intl.ListFormat:

https://github.com/tc39/proposal-intl-list-format

@ByteEater-pl
Copy link
Author

ByteEater-pl commented Feb 13, 2019

This is actually implemented in a different Stage 3 proposal:

https://github.com/tc39/proposal-intl-relative-time

That's what I was referring to.

This is covered by unit formatting
When combining multiple such units, you can use Intl.ListFormat

These are separate features. What this issue is about is a combination of both specialized for time intervals. E.g. programmers shouldn't need to know the list of units involved. (I imagine one in 59 s, two in 61 s and possibly one or two, depending on an option, in 1.5 s. The number of units used may even be, especially for fractions, locale dependent.)

I also take back the "two years and five days" example. I recalled the distinction in the SQL standard between year-month and day-time intervals which cannot be mixed (since months differ in number of days) and it occurred to me that ECMAScript should follow suit.

@littledan
Copy link
Member

There was some past discussion about DurationFormat, I think. Is this subsumed by unit formatting? I thought some formats for durations were not, e.g., time remaining watching a video, but the cases that this issue starts with may fit into the same larger framework.

As for a high level API that removes the need for computations: we are generally focused on starting with low-level APIs here, to give application developers the most flexibility.

@sffc
Copy link
Contributor

sffc commented Feb 28, 2019

Good point. Numeric durations are supported in ICU MeasureFormat (internally the implementation is a bit of a hacky wrapper around DateFormat), but not in the proposals I listed previously.

@sffc
Copy link
Contributor

sffc commented Feb 28, 2019

FWIW, I might support a feature like formatDuration on Intl.DateTimeFormat to support this, where that function always uses the numeric format (hh:mm:ss localized as needed). The non-numeric formats for durations (5h 10m 13s) can continue to go through the Intl.ListFormat+Intl.NumberFormat code path suggested above.

@sffc sffc added c: datetime Component: dates, times, timezones and removed c: datetime Component: dates, times, timezones labels Mar 19, 2019
@sffc
Copy link
Contributor

sffc commented Mar 19, 2019

Closing this as a duplicate of #47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants