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().format() incorrect on older browsers #4803

Closed
Unsfer opened this issue Oct 9, 2018 · 6 comments
Closed

moment().format() incorrect on older browsers #4803

Unsfer opened this issue Oct 9, 2018 · 6 comments

Comments

@Unsfer
Copy link

Unsfer commented Oct 9, 2018

Description of the Issue and Steps to Reproduce:
When converting to 'DD.MM.YYYY' format some rare dates becomes new, not equal to the initial

var date = "1983-04-01";
var ruDate = moment(date, 'YYYY-MM-DD').format('DD.MM.YYYY');
alert(date + " - " + ruDate);
// Output: "1983-04-01 - 31.03.1983"

http://jsfiddle.net/f3jus6cn/

Environment:
Reproduced this on Chromium 35 and Firefox 45.9.0
OS: Gentoo 2.2

Other information that may be helpful:

  • The time zone setting: +0400
  • The time and date at which the code was run: doesn't matter
@ashsearle
Copy link
Contributor

Please can you run the code below and tell us the output:

var date = "1983-04-01";
var ruDate = moment(date, 'YYYY-MM-DD');
console.log(moment.version, moment.locale(), ruDate.toISOString(), ruDate.toDate().toString());

@Unsfer
Copy link
Author

Unsfer commented Oct 11, 2018

moment.version: "2.2.1"
moment.locale(): error moment.locale is not a function
toISOString: "1983-03-31T19:00:00.000Z"
toDate: "Thu Mar 31 1983 23:00:00 GMT+0400 (KUYT)"

@ashsearle
Copy link
Contributor

moment 2.2.1 - from September 2013?

You should probably upgrade and see if the bug is fixed in a more recent version of moment.

@Unsfer
Copy link
Author

Unsfer commented Oct 11, 2018

Tried latest version:

moment.version: "2.22.2"
moment.locale(): "ru"
toISOString: "1983-03-31T19:00:00.000Z"
toDate: "Thu Mar 31 1983 23:00:00 GMT+0400 (KUYT)"

@ashsearle
Copy link
Contributor

Interesting. Daylight savings time started at midnight beginning 1st April 1983, so clocks moved forward to 1AM.

moments represent a date and a time. 1983-04-01 is effectively shorthand for trying to create a moment at 00:00:00 in local time. But, that date + time doesn't exist in your locale.

This sounds very similar to a Brazil DST issue, so this might be fixed if PR #4338 gets merged.

@marwahaha
Copy link
Member

I think this is working now (2.24.0).

Please re-open if you still have issues.

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

No branches or pull requests

3 participants