-
Notifications
You must be signed in to change notification settings - Fork 599
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
Implement DateTimeFormat.format for non android/ios environments #1362
Conversation
Versions before 67 had a bug with defaults, where they were adding the `yes` and `true` defaults to Language Tags. See unicode-org/icu#952 for their fix.
Hey @manuelpuyol, it's exciting to see this progress! I noticed you're sharing code differently than the original MS implementation, and I wanted to suggest a further slight tweak that will allow much more code to live in This is just something to consider as you're thinking about it, but we can move forward with this PR regardless of whether you adopt it. The main idea is to have So using PlatformIntlShared.h:
PlatformIntlShared.cpp
PlatformIntlICU.cpp
|
I've been thinking more about the "Shared" implementation... If the goal is to migrate everything to ICU in the future, won't the Apple and Android implementations be deprecated? At that point having a shared library may be more burdensome that helpful since it does introduce extra code complexity. So maybe it's worth getting rid of However, if you feel like that's a distant future, I'd be happy to work on a better code sharing strategy, though I think that'd be more appropriate in a follow-up PR if that's ok for you :) |
@manuelpuyol Of course, let's worry about that later |
Co-authored-by: neildhar <neildhar@users.noreply.github.com>
Follow Apple's implementation and substitute NS calls with ICU calls for defaults and available locales
Ported from hermes-windows
Implementation was copied from Apple's implementation
Ported from hermes-windows
4d28ef7
to
0158c22
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together @manuelpuyol!
I was just doing a first pass over this and was wondering if there is a reason we need UTF-16 <> UTF-8 conversion at all here? It seems like it is only used for locale identifiers and timezones, which should all be ASCII.
I'm gonna take a look at the apple test! As for the test262:
|
mind sharing a specific example I can take a look? |
@manuelpuyol has updated the pull request. You must reimport the pull request before landing. |
Sure, if you run |
@manuelpuyol has updated the pull request. You must reimport the pull request before landing. |
@neildhar I'm noticing that |
Minor differences are inevitable, we should relax the match patterns slightly where necessary to accommodate those differences, since they likely just come up from different ICU versions being used. We run this test using It should just be a matter of turning a few characters into wildcards. If the differences are more substantial, that may indicate a bug in one of the implementations. |
just to keep track of it, these are the differences I'm seeing in that test: const date = new Date(Date.UTC(2020, 0, 2, 3, 45, 00, 30));
const oldDate = new Date(Date.UTC(1952, 0, 9, 8, 04, 03, 05));
// apple and node: 3
// ICU: 03
new Intl.DateTimeFormat('en-GB', {second: '2-digit'}).format(oldDate)
// apple: 午前3:45
// ICU and node: 3:45
new Intl.DateTimeFormat('ja-JP', {hour: 'numeric', minute: 'numeric'}).format(date);
// apple: 午前3:45
// ICU and node: 03:45
new Intl.DateTimeFormat('ja-JP', {hour: '2-digit', minute: '2-digit'}).format(date);
// apple and ICU: zh
// node: zh-CN
new Intl.DateTimeFormat('zh-CN').resolvedOptions().locale
// apple and ICU: undefined
// node: latn
new Intl.DateTimeFormat('en-US').resolvedOptions().numberingSystem;
// apple: SGT
// node and ICU: Error Invalid time zone specified
new Intl.DateTimeFormat('en-US', { timeZone: 'SGT'}).resolvedOptions().timeZone |
@neildhar if you are comfortable with those differences, I can push a change to the test :) |
The Japanese date patterns seem potentially wrong. It looks like the DateTime pattern generation here doesn't quite follow the spec rules. For example, the 23 hour cycle should be using |
@manuelpuyol has updated the pull request. You must reimport the pull request before landing. |
indeed! I updated it and now ICU outputs the same as node for that case |
The rest seem to be genuine differences in the defaults. We don't need to solve this right away though, given that the implementation is incomplete (so we can't run tests anyway). |
@neildhar has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@manuelpuyol has updated the pull request. You must reimport the pull request before landing. |
@neildhar has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
d987fef
to
d9f5286
Compare
@manuelpuyol has updated the pull request. You must reimport the pull request before landing. |
Related to #1350 and #1211
Follow up of #1361
Summary
I'd like to expand non iOS/android support of
Intl
. In this case, I'm implementing bothDateTimeFormat.prototype.resolvedOptions
andDateTimeFormat.prototype.format
. The implementation is a mix from the Apple and hermes-windows' implementations.PlatformIntlShared
with helper functions that are exactly the same between Apple and ICUDateTimeFormatICU
based onDateTimeFormatApple
Test Plan
Testing against
test262/test/intl402/DateTimeFormat