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

Parse date using timezone return different values based on format #790

Closed
MCFreddie777 opened this issue Oct 18, 2019 · 3 comments
Closed
Labels

Comments

@MCFreddie777
Copy link

Parsing date using timezone returns different output if used with and without date format.

Current result:

moment.tz("18 Oct 2019, 15:40:42", "Europe/London").valueOf()
1571413242000
moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "Europe/London").valueOf()
1571409642000

Expected result:

moment.tz("18 Oct 2019, 15:40:42", "Europe/London").valueOf()
1571409642000
moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "Europe/London").valueOf()
1571409642000

This does not look like expected behaviour.
Result of converting date based on timezone should not be dependent on date formatting.

@thiagozampieri
Copy link

thiagozampieri commented Oct 28, 2019

The problem is that moment-timezone only accepts auto parse for RFC2822 or ISO format.

var moment1 = moment.tz("2019-10-18T15:40:42", "America/New_York").valueOf();
var moment2 = moment.tz("18 Oct 2019, 15:40:42", "DD MMM YYYY, hh:mm:ss", "America/New_York").valueOf();

@ellenaua ellenaua added the bug label Mar 14, 2020
@ellenaua
Copy link
Contributor

This is the same bug as #807 - @todo fix it

@ichernev
Copy link
Contributor

This is not an issue, just don't assume your format is handled by moment, because it will silently be passed on to Date and all bets are off. There is a reason moment constructor outputs warnings if that happens. We should just introduce new constructors which disable this behavior (passing to Date and hoping for the best).

TLDR -- if you KNOW the format, pass it. If you don't know the format, don't get upset when it's not parsed correctly. Every single country has it's own standards and rituals of writing dates, moment (and Date) can't possibly know what you mean.

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

No branches or pull requests

4 participants