tc39 / proposal-intl-relative-time

`Intl.RelativeTimeFormat` specification [draft]
http://tc39.github.io/proposal-intl-relative-time/
215 stars 24 forks source link

[future] Add time formatting option #10

Open zbraniecki opened 7 years ago

zbraniecki commented 7 years ago

CLDR and ICU provide as part of the RelativeDateTimeFormatter API an option to format time together with the date to produce strings like tomorrow at 3 pm or today at 3:45 pm.

Since we pass Date object as parameter already, all we really have to do is enable formatting of that.

My suggestion is to add hour, minute, second and hourCycle as options for RelativeTimeFormat.

Example:

let rtf = new Intl.DateTimeFormat('en-US', {
  hour: 'numeric'
});

rtf.format(new Date() + 1000 * 60 * 60 * 24); // 'tomorrow at 3 pm'
let rtf = new Intl.DateTimeFormat('en-US', {
  hour: 'numeric',
  minute: 'numeric'
});

rtf.format(new Date() + 1000 * 60 * 60 * 24); // 'tomorrow at 3:45 pm'

by default those options would be undefined and no date+time formatting would happen.

I suggest that we keep this idea for second revision of the API, but wanted to propose it already to put it in scope of any API conversations.

zbraniecki commented 7 years ago

Alternatively, we could land this API on DateTimeFormat because one other form that it could be use with is Monday at 2pm or Monday, January 3rd at 3:45pm.

So it's less about relative, and more about human readable form of combining date and time where date can be absolute (Monday, January 4th) or relative (Tomorrow). The en-US pattern for this in CLDR 30 looks like this: http://www.unicode.org/cldr/charts/30/summary/en.html#1825

Thoughts?

rxaviers commented 7 years ago

it's less about relative, and more about human readable form of combining date and time where date can be absolute (Monday, January 4th) or relative (Tomorrow).

:+1: