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

bug report: moment.tz format has some bug , unexpected year number 0002 #1115

Open
Zola opened this issue Aug 3, 2024 · 1 comment
Open

Comments

@Zola
Copy link

Zola commented Aug 3, 2024

Environment

For bug reports, please run the following code in your environment and include the output:

console.log({
  moment: moment.version,
  momentTz: moment.tz.version,
  date: (new Date()).toString(),
  intlZone: new Intl.DateTimeFormat().resolvedOptions().timeZone,
});

{moment: "2.29.1", momentTz: "0.5.34", date: "Sun Aug 04 2024 03:28:32 GMT+0800 (台北標準時間)", intlZone: "Asia/Taipei"}

Issue description

moment.tz('2:05 PM · Nov 12, 2010 ', ' h:mm A · MMM D, YYYY', 'America/New_York') ,
0002-05-12 20:10:00 , should be 2010, not 0002, I think the code may have some bug to fix.

the moment.min.js are fine to format string
moment('2:05 PM · Nov 12, 2010 ', ' MMMM D, YYYY h:mm A', true);
2010-11-12 14:05:00

same result with js from momentjs.com

<script src="https://momentjs.com/downloads/moment.js"></script>
<script src="https://momentjs.com/downloads/moment-timezone-with-data.js"></script>
@gilmoreorless
Copy link
Member

I think you need to be careful with leading and trailing spaces in your format strings. When I run your examples in the browser console on https://momentjs.com, I don't see the year 0002, but I do see some weirdness. But removing the space at the start of the format strings makes everything work.

moment.tz('2:05 PM · Nov 12, 2010 ', ' h:mm A · MMM D, YYYY', 'America/New_York').format();
// "2024-08-05T12:20:00-04:00", completely wrong

// NOTE: No space at the start ------👇 
moment.tz('2:05 PM · Nov 12, 2010 ', 'h:mm A · MMM D, YYYY', 'America/New_York').format();
// "2010-11-12T14:05:00-05:00", correct

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