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

Parsing localized time string including meridiem with format 'a hh:mm' ignores meridiem. #2031

Open
rodumani opened this issue Aug 20, 2022 · 1 comment

Comments

@rodumani
Copy link

Describe the bug

Parsing localized time string including meridiem with format 'a hh:mm' ignores meridiem.

In Korean, "am" is "오전" and "pm" is "오후". There is no uppercase/lowercase in Korean.

However, dayjs customParseFormat doesn't recognize the meridiem and only returns hours in am.

Expected behavior
A clear and concise description of what you expected to happen.

import dayjs from 'dayjs';
import 'dayjs/locale/ko.js';

import customParseFormat from 'dayjs/plugin/customParseFormat.js';
dayjs.extend(customParseFormat);

const amStr = '오전 10:00';
const pmStr = '오후 10:00';
const format = 'a h:mm';

const am = dayjs(amStr, format);
console.assert(am.hour() === 10, 'am.hour() === 10');
const pm = dayjs(pmStr, format);
console.assert(pm.hour() === 22, 'pm.hour() === 22');
$ node index.js
Assertion failed: pm.hour() === 22

The second assert should be passed, but it fails because it returns the hour as 10.

Information

  • Day.js Version: 1.11.5
  • OS: macOS 12.5
  • Browser: Node v16.14.0 / Chrome 104.0.5112.101
  • Time zone: GMT +09:00 KST
@BePo65
Copy link
Contributor

BePo65 commented Sep 26, 2022

The problem stems from the fact that CustomPareFormat tries to implement some kind of a 'meridiemParse' function that uses the 'meridiem' function of the locale file to find out which hour values are considered 'am' and 'pm'. This function supposes that the 'meridiem' function returns the string for 'pm' for anything after '12' and the string for 'am' for hours '12' and before.

But some locales consider noon as 'pm' among them 'ko'.

If we look to the details of meridiem then we will find that noon / midnight is a very problematic case (and that the chinese locales use more verbs for time ranges, not only 'am' and 'pm'). Details can be found e.g. in wikipdia.

The question is, if we need some kind of 'meridiemParse' function like moment does. @iamkun any opinion on this? I think this would not be too problematic.

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