Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

[future] Add time formatting option #10

Open
zbraniecki opened this issue Jan 16, 2017 · 2 comments
Open

[future] Add time formatting option #10

zbraniecki opened this issue Jan 16, 2017 · 2 comments

Comments

@zbraniecki
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member

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).

👍

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

No branches or pull requests

4 participants