-
Notifications
You must be signed in to change notification settings - Fork 187
Use Intl.RelativeTimeFormat #104
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,3 +164,23 @@ export function isThisYear(date: Date) { | |
| const now = new Date() | ||
| return now.getUTCFullYear() === date.getUTCFullYear() | ||
| } | ||
|
|
||
| // eslint-disable-next-line flowtype/no-weak-types | ||
| export function makeRelativeFormatter(options: any): () => ?any { | ||
| let format | ||
| return function() { | ||
| if (format) return format | ||
| if ('Intl' in window && 'RelativeTimeFormat' in window.Intl) { | ||
| try { | ||
| // eslint-disable-next-line flowtype/no-flow-fix-me-comments | ||
| // $FlowFixMe: missing RelativeTimeFormat type | ||
| format = new Intl.RelativeTimeFormat(undefined, options) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm down to support that, though I was just stealing from our existing Will that need to change as well? Should I do this in a separate PR? Starting to wonder how this change is going to ship. It might be a major version bump. So could bundle this and that locale change in one release.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the runtime's default locale is hardcoded to A major version release would be appropriate since this changes the text output slightly. We could couple that with |
||
| return format | ||
| } catch (e) { | ||
| if (!(e instanceof RangeError)) { | ||
| throw e | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.