-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Preparse postformat + implementation in ar locale + tests #1255
Conversation
Update recent changes in main branch for merging to dev branch
Codecov Report
@@ Coverage Diff @@
## dev #1255 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 174 175 +1
Lines 1653 1697 +44
Branches 374 387 +13
=========================================
+ Hits 1653 1697 +44
Continue to review full report at Codecov.
|
@iamkun just making sure: is there something that needs fixing / changing before this can be committed? |
First of all, thanks for this PR. One thing I did not get clearly is, seems it changed the original code too much to support this feature. And I'm afraid I did not know this issue much. Any more detail you can give us, please? Or is it better for us to leave it as a separate plugin package? |
Hi @iamkun - the changes to the original code are because I did a merge commit to my branch following a change you've made to the dev branch (commit acd8736). I did it to ensure my code will merge well with the branch. I can try to create a new pull request without the merge commit if it's confusing - I was only trying to ensure tests pass with the most recent code. I don't think it should mess anything up frankly... The only manual change I made to existing (plugin) code was to the relative time plugin, where I made an inner logic overridable through the prototype chain to support postFormatting (see fromToBase in the relativeTime changes). Let me know how you want me to proceed :) |
Ok, I see. How should we use this plugin? As far as I can see, if I want to get the correct It's a little bit wired to me, to be honest. |
The plugin works fine with or without the relative time component. It is not a requirement. |
Then what's this plugin used for? I've checked the code and think it might be related to Correct me if I am wrong. |
Now I understand the confusion. Preparse / postformat is a feature in moment that lets you process the input before the parser and process the string output after the formatter. In the AR locale specifically, it is used to support Arabic numerals (see the last two commits). I needed to include support for the relative time plugin because in moment it is also processed by this logic. |
It is also used in other locales an I personally used it in a custom locale for work on moment |
Thanks for this background information. As I am not familiar with the concept, could you please give some reference of moment.js in this topic we've talked about? This could give me a more detailed understanding of this PR. |
In the docs: https://momentjs.com/docs/#/i18n/locale-data/ In the code: https://github.com/moment/moment/blob/b7ec8e2ec068e03de4f832f28362675bb9e02261/moment.js Moment.js test (on which I based the dayjs tests - commit |
THX. I'll take a look at the doc you've provied. |
Did you get a chance to look at the references? |
export default (option, dayjsClass, dayjsFactory) => { | ||
// This plugin depends on other plugins - so I will import them here | ||
// equivalent to dayjsClass.extend(duration) | ||
localeData(option, dayjsClass, dayjsFactory) |
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.
we don't have to import other plugins like this.
Just listing the dependent plugin in the doc.
Yes, it looks good to me. If I want to get the correct ar locale result, should I use it in this way
|
You actually don't need to extend localeData, the plugin takes care of it for you. The ar tests I've added demonstrate the usage of the plugin (a5b9200). |
Yes, you can see the comment above, I don't think it's a good idea to import localeData plugin into this plugin |
I don't mind fixing this (it's quite simple) but I think it's a bad idea for two reasons:
Let me know what you think - if you insist I will of course conform to your decision :) Best regards and happy new year! |
Cause by design, a plugin could be dependent on another one. https://day.js.org/docs/en/plugin/advanced-format Check format Week of year as an example here. |
As I said - it's a pretty simple fix. I've made it and tests seem to still pass. Let me know if you need me to make any additional changes. |
LGTM. Let get this version released and see if there's any improvement that we could do. |
# [1.10.0](v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](#1266)) ([fd229fa](fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](#1255)) ([f2e4790](f2e4790)) * add type support for plural forms of units ([#1289](#1289)) ([de49bb1](de49bb1)) * escape last period to match only milliseconds ([#1239](#1239)) ([#1295](#1295)) ([64037e6](64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](#1298)) ([f63375d](f63375d)), closes [#598](#598) [#313](#313)
🎉 This PR is included in version 1.10.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [1.10.0](iamkun/dayjs@v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](iamkun/dayjs#1266)) ([fd229fa](iamkun/dayjs@fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](iamkun/dayjs#1255)) ([f2e4790](iamkun/dayjs@f2e4790)) * add type support for plural forms of units ([#1289](iamkun/dayjs#1289)) ([de49bb1](iamkun/dayjs@de49bb1)) * escape last period to match only milliseconds ([#1239](iamkun/dayjs#1239)) ([#1295](iamkun/dayjs#1295)) ([64037e6](iamkun/dayjs@64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](iamkun/dayjs#1298)) ([f63375d](iamkun/dayjs@f63375d)), closes [#598](iamkun/dayjs#598) [#313](iamkun/dayjs#313)
# [1.10.0](iamkun/dayjs@v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](iamkun/dayjs#1266)) ([fd229fa](iamkun/dayjs@fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](iamkun/dayjs#1255)) ([f2e4790](iamkun/dayjs@f2e4790)) * add type support for plural forms of units ([#1289](iamkun/dayjs#1289)) ([de49bb1](iamkun/dayjs@de49bb1)) * escape last period to match only milliseconds ([#1239](iamkun/dayjs#1239)) ([#1295](iamkun/dayjs#1295)) ([64037e6](iamkun/dayjs@64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](iamkun/dayjs#1298)) ([f63375d](iamkun/dayjs@f63375d)), closes [#598](iamkun/dayjs#598) [#313](iamkun/dayjs#313)
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.
LGTM
# [1.10.0](iamkun/dayjs@v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](iamkun/dayjs#1266)) ([fd229fa](iamkun/dayjs@fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](iamkun/dayjs#1255)) ([f2e4790](iamkun/dayjs@f2e4790)) * add type support for plural forms of units ([#1289](iamkun/dayjs#1289)) ([de49bb1](iamkun/dayjs@de49bb1)) * escape last period to match only milliseconds ([#1239](iamkun/dayjs#1239)) ([#1295](iamkun/dayjs#1295)) ([64037e6](iamkun/dayjs@64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](iamkun/dayjs#1298)) ([f63375d](iamkun/dayjs@f63375d)), closes [#598](iamkun/dayjs#598) [#313](iamkun/dayjs#313)
Added a plugin to implement the preparse / postformat functions for locales such as "ar", based on the moment implementation. I added tests for both the plugin and the locale changes based on the moment tests.
This should solve #416
Do note that the relative time implementation for the ar locale does not match the moment one, so the tests for the locale are different (to focus on coverage and not correctness tests - since I am not an arabic speaker and could not fix the relative time implementation in the scope of this change).