Skip to content
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

add zh locale #822

Merged
merged 4 commits into from
Mar 10, 2020
Merged

add zh locale #822

merged 4 commits into from
Mar 10, 2020

Conversation

ZYinMD
Copy link
Contributor

@ZYinMD ZYinMD commented Mar 7, 2020

In window.navigator.languages in Chrome, there are 4 valid Chinese locales that could appear: zh, zh-cn, zh-cn, zh-hk. Currently zh is missing from dayjs. This PR adds the zh locale.

zh has some minor improvements over the other 3 locales. For developers, this won't affect your existing code, but if you start using zh, your output will be slightly more correct in some occasional cases.

For example:

// no more unecessary whitespace:
dayjs().locale('zh-cn').subtract(7, 'month').fromNow() // 7 个月前
dayjs().locale('zh').subtract(7, 'month').fromNow() // 7个月前

// use "后" instead of "内" for relative future:
dayjs().locale('zh-cn').add(3, 'day').fromNow() // 3 天内
dayjs().locale('zh').add(3, 'day').fromNow() // 3天后

// improve ordinal week of year:
dayjs('2020-10-13').locale('zh-tw').format('wo') // 42日 // wrong
dayjs('2020-10-13').locale('zh-hk').format('wo') // 42日 // wrong
dayjs('2020-10-13').locale('zh-cn').format('wo') // 42周 // ok
dayjs('2020-10-13').locale('zh').format('wo') // 第42周 // better

issue #820

In Chrome, in window.navigator.languages, there are 4 valid Chinese locales that could appear: zh, zh-CN, zh-TW, zh-HK. Currently zh is missing from dayjs. This PR adds the zh locale.

The zh locale has some minor improvements over the other 3. For developers, this won't affect your existing code, but if you start using zh, your output will be slightly more correct in some occasional cases.
@codecov
Copy link

codecov bot commented Mar 7, 2020

Codecov Report

Merging #822 into dev will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff         @@
##            dev   #822   +/-   ##
===================================
  Coverage   100%   100%           
===================================
  Files       157    158    +1     
  Lines      1148   1165   +17     
  Branches    215    222    +7     
===================================
+ Hits       1148   1165   +17
Impacted Files Coverage Δ
src/locale/zh.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b54150e...5a2fa81. Read the comment docs.

@iamkun
Copy link
Owner

iamkun commented Mar 8, 2020

please add test

@ZYinMD
Copy link
Contributor Author

ZYinMD commented Mar 9, 2020

Honestly I looked everywhere in the codebase and didn't find how it should be tested, and why existing tests are not passing... I compared with #516, which didn't add any tests either, and seems it did exactly the same thing as this one.

哭了

@iamkun
Copy link
Owner

iamkun commented Mar 9, 2020

test/locale/zh-cn.test.js

@iamkun
Copy link
Owner

iamkun commented Mar 10, 2020

Cool, I'll keep the same at this moment. And update it all together later.

@iamkun iamkun merged commit 9dd69ed into iamkun:dev Mar 10, 2020
@iamkun
Copy link
Owner

iamkun commented Mar 16, 2020

🎉 This PR is included in version 1.8.23 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants