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

Moment.js Locale Override Mystery - AM/PM Parsing Gone Wrong!" #6234

Open
shakeelkoper opened this issue May 15, 2024 · 0 comments
Open

Moment.js Locale Override Mystery - AM/PM Parsing Gone Wrong!" #6234

shakeelkoper opened this issue May 15, 2024 · 0 comments

Comments

@shakeelkoper
Copy link

Describe the bug
The moment().locale() function is not able to override the locale from 'ja' to 'en' for a specific instance. As a result, it's not able to correctly parse the "AM/PM" part of a UTC date-time string. ex: '5/11/2024 3:00:31 PM'

To Reproduce
Steps to reproduce the behavior:

  1. Set the global locale to 'ja' using moment.locale('ja').
  2. Try to parse a date-time string in English format with the "AM/PM" part, using moment().locale('en').
    ex:moment("5/11/2024 3:00:31 PM", "M/D/YYYY h:mm:ss a").locale('en').utcOffset(0, true).unix()
  3. The "AM/PM" part is not parsed correctly, as indicated by unusedInput:["PM"] and unusedTokens: ["a"].

Expected behavior
The moment().locale('en') function should override the global locale for the specific instance, allowing the "AM/PM" part of the date-time string to be parsed correctly.
1715439631 -> Saturday, 11 May 2024 15:00:31

Wrong behavior
1715396431 -> Saturday, 11 May 2024 03:00:31

Desktop (please complete the following information):

  • OS: macOS 14.4.1 (23E224)
  • Node.js version: v16.20.2
  • Moment.js version: 2.30.1

Moment-specific environment

  • The time zone setting of the machine the code is running on: [e.g. JST]
  • The time and date at which the code was run: [e.g. '5/10/2024 8:58:17 PM']
  • Other libraries in use: moment-duration-format 2.3.2, moment-timezone 0.5.34

Please run the following code in your environment and include the output:

console.log((new Date()).toString()) //'Thu May 16 2024 01:28:31 GMT+0530 (India Standard Time)'
console.log((new Date()).toLocaleString()) //'16/05/2024, 01:28:47'
console.log((new Date()).getTimezoneOffset()) //-330
console.log(process.version)
console.log(moment.version) //'2.30.1'
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
@shakeelkoper and others