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

Time validation not working properly for languages does not have AM/PM #2442

Open
ahamedalthaf opened this issue Sep 7, 2023 · 3 comments
Open

Comments

@ahamedalthaf
Copy link

ahamedalthaf commented Sep 7, 2023

Time formatting not working properly for languages that has different value apart from AM and PM for meridiem.

Ex:

Japanese Language:

Current:
dayjs('9:00 午後', 'h:mm A', 'ja').format('h:mm A') - 9:00 午前 (Wrong)

The value should be like below.
dayjs('9:00 午後', 'h:mm A', 'ja').format('h:mm A') - 9:00 午後 (Correct)

Information

Day.js Version: 1.11.9,
OS: MacOs

@Pareder
Copy link

Pareder commented Sep 8, 2023

@iamkun I think the problem is in CustomParseFormat plugin. It determines afternoon by such condition https://github.com/iamkun/dayjs/blob/dev/src/plugin/customParseFormat/index.js#L55 (i > 12), but meridiem method of locale returns 12 for afternoon (https://github.com/iamkun/dayjs/blob/dev/src/locale/ja.js#L24), so we will get i === 12 and in this case this.afternoon is false.

Also there are some locales that have more than two periods, not only AM/PM, for example zh-cn, bn-bd, etc. and this method is broken for such locales.

@ahamedalthaf
Copy link
Author

For other locales, there is no value in between 11 and 12 so it should not be a problem. This problem will come only for three languages as of now. 'zh', 'zh-cn', 'zh-tw'

@ahamedalthaf
Copy link
Author

Have added relevant changes and added tests for the same. Please check once @iamkun
#2443

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

No branches or pull requests

2 participants