-
Notifications
You must be signed in to change notification settings - Fork 648
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
fix: signDisplay plus sign behaviour fixed for NumberFormat #1483
fix: signDisplay plus sign behaviour fixed for NumberFormat #1483
Conversation
@tmikov Whenever you have time, can you please check this PR? It solves the |
Hey @shubhamguptadream11, thank you for looking into this and submitting this PR! Could you describe the exact change here in more detail? It looks like there is more going on with this change, with regards to whether the positive/negative strings are checked and whether things are added to the suffix or prefix. Alternatively, it looks like Android API level 31 adds native support for this functionality. I think it would be preferable to add an API version check and use the newer API when possible, which should be available on most devices. |
Looks great! It looks like CI is failing, likely because the compile/target SDK version specified in our |
Hi @neildhar, I attempted to upgrade the Could someone from the Hermes team take on the task of upgrading the compile/target version to the latest supported? or help me in upgrading that. Once that's done, I'll be able to raise my PR. Till then I am trying to fix deprecated API's. Thanks! |
Hi @neildhar , I've finally fixed all the errors that emerged due to the compile SDK upgrade. Below is a summary of the changes made: Migration to JUnit4 and AndroidJUnitRunner: Replaced the deprecated InstrumentationTestCase with the recommended JUnit4 and AndroidJUnitRunner. Updated Hermes Tests: Addressed issues related to missing JSRuntime references by correctly importing and using it within test files. Please take a moment to review these changes and let me know if any further adjustments are needed. Thanks for your guidance and support throughout this process! |
@shubhamguptadream11, thanks for bumping the SDK version and fixing up the deprecated APIs. Everything looks good, please add a test and update the summary, and I'll merge this. |
@neildhar Added test cases and updated PR summary as well. Please check and let me know if anything else needed from my end. |
Hi @neildhar Just wanted to follow up on this PR. I’ve added the test cases and updated the summary as discussed. Could you please review it when you get a chance? Let me know if there’s anything else you need from my side. Thanks again for your time! |
if (Build.VERSION.SDK_INT >= 31) { | ||
try (JSRuntime rt = JSRuntime.makeHermesRuntime()) { | ||
rt.evaluateJavaScript( | ||
"var nf = new Intl.NumberFormat('de-DE', { exceptZero: 'never', currency: 'EUR' });\n" + |
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.
This test seems odd, is it correct? I'm not aware of exceptZero
being an option to NumberFormat
(as opposed to signDisplay: "exceptZero"
), and I don't believe the currency is printed unless you set style: "currency"
.
If this is incorrect, we should understand why this test didn't fail.
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.
I've corrected the test case to properly reflect the intended behaviour by using signDisplay: 'exceptZero' and including the style: 'currency' option.
Hi @neildhar , Could we please check and review this PR when you have a moment? |
@shubhamguptadream11 Could you clarify if the test is actually running or if you ran it locally? It seems odd that the previous version of the test was working. |
@neildhar Command Used:
With previous faulty test cases
Test cases are failing in local: With updated test cases: |
@neildhar Please check the PR once. I had shared few screenshots above about test cases results. |
@neildhar has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi @neildhar Thank you for your time and support! |
@shubhamguptadream11 has updated the pull request. You must reimport the pull request before landing. |
Hi @neildhar, I hope you are doing well. Can you please take a moment to review this PR. |
…1483) Summary: Original Author: 85783070+shubhamguptadream11@users.noreply.github.com Original Git: a75e14a Original Reviewed By: avp Original Revision: D62153166 Fixes following issue: - #1466 - #1138 - #789 **Why this change is made?** There are few cases where signDisplay is not being handled correctly. Examples: ``` 1. new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR', signDisplay: 'exceptZero', }).format(8537.71) Output: +8,537,71+ Expected: +8.537,71 € 2. new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY', signDisplay: 'exceptZero' }).format(123456.789) Output: +123,457 Expected: +¥123,457 ``` **ChangeLog** This PR updates the implementation and testing of the signDisplay functionality in the DecimalFormat class within the Hermes engine, specifically for Android API level 31 and above. **Key Changes:** Implementation: - Integrated the **setSignAlwaysShown** method of DecimalFormat for API level 31 and above to control the display of the sign (+ or -) based on the signDisplay option. [For more detail about setSignAlwaysShown check [here](https://developer.android.com/reference/android/icu/text/DecimalFormat#setSignAlwaysShown(boolean))] - For API levels below 31, maintained the existing logic for handling sign display, ensuring backward compatibility. Pull Request resolved: #1483 Pulled By: neildhar Reviewed By: neildhar Differential Revision: D62883944 fbshipit-source-id: df41029b45400b9db038f32727293d5ccda27211
Summary
Fixes following issue:
Why this change is made?
There are few cases where signDisplay is not being handled correctly.
Examples:
ChangeLog
This PR updates the implementation and testing of the signDisplay functionality in the DecimalFormat class within the Hermes engine, specifically for Android API level 31 and above.
Key Changes:
Implementation:
Test Plan
NEVER | ALWAYS | EXCEPTZERO