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

morebits.date: Fix bug parsing parens around UTC timestamps #921

Merged

Conversation

Amorymeltzer
Copy link
Collaborator

Not sure how this was missed in #814, but js date will see the parentheses in (UTC) and completely ignore the whole thing, setting the timezone local. Should cause issues anywhere, but particularly problematic for the warn module.

Vaguely related discussion: https://github.com/azatoth/twinkle/pull/814/files#r374359937

Not sure how this was missed in wikimedia-gadgets#814, but js date will see the parentheses in `(UTC)` and completely ignore the whole thing, setting the timezone local.  Should cause issues anywhere, but particularly problematic for the warn module.

Vaguely related discussion: https://github.com/azatoth/twinkle/pull/814/files#r374359937
@Amorymeltzer Amorymeltzer added this to the April 2020 update milestone Apr 13, 2020
@Amorymeltzer Amorymeltzer added bug Module: morebits The morebits.js library labels Apr 13, 2020
// Try again after removing a comma, to get MediaWiki timestamps to parse
this._d = new (Function.prototype.bind.call(Date, Date, args[0].replace(/(\d\d:\d\d),/, '$1')));
// Try again after removing a comma and paren-wrapped timezone, to get MediaWiki timestamps to parse
this._d = new (Function.prototype.bind.call(Date, Date, args[0].replace(/(\d\d:\d\d),/, '$1').replace(/\(UTC\)/, 'UTC')));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this._d = new (Function.prototype.bind.call(Date, Date, args[0].replace(/(\d\d:\d\d),/, '$1').replace(/\(UTC\)/, 'UTC')));
this._d = new (Function.prototype.bind.call(Date, Date, args[0].replace(/(\d\d:\d\d),/, '$1').replace(/\(UTC\)$/, 'UTC')));

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably unnecessary, if it ever came up, it wouldn't be detected as a date anyway.

@Amorymeltzer Amorymeltzer changed the title morebits: Fix bug parsing parens around UTC timestamps morebits.date: Fix bug parsing parens around UTC timestamps Apr 13, 2020
@Amorymeltzer Amorymeltzer merged commit ad5c11c into wikimedia-gadgets:master Apr 21, 2020
@Amorymeltzer Amorymeltzer deleted the morebits-fixutcbug branch April 21, 2020 01:27
Amorymeltzer added a commit to Amorymeltzer/twinkle that referenced this pull request May 3, 2020
See https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:Twinkle&oldid=954707038

As noted in wikimedia-gadgets#921, mediawiki on enwiki uses dates formatted like `19:37, 3 May 2020 (UTC)`, which is an invalid date for two reasons. The first is that (UTC±offset) isn't correct for a timezone, and the native Date converts it to a local date; that is, 17:00 (UTC) become 17:00 (local). The second is that the comma after the time is just plain wrong. Twinkle's new date function handles both of those, except that apparently Firefox 75 will actually now accept the comma as valid. Thus, Firefox was short-circuiting our initial check to see if we had a valid date, before we could clean up mediawiki's parenthesis crap, which was leading to local timezone issues.
wiki-ST47 pushed a commit to wiki-ST47/twinkle that referenced this pull request Sep 2, 2020
See https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:Twinkle&oldid=954707038

As noted in wikimedia-gadgets#921, mediawiki on enwiki uses dates formatted like `19:37, 3 May 2020 (UTC)`, which is an invalid date for two reasons. The first is that (UTC±offset) isn't correct for a timezone, and the native Date converts it to a local date; that is, 17:00 (UTC) become 17:00 (local). The second is that the comma after the time is just plain wrong. Twinkle's new date function handles both of those, except that apparently Firefox 75 will actually now accept the comma as valid. Thus, Firefox was short-circuiting our initial check to see if we had a valid date, before we could clean up mediawiki's parenthesis crap, which was leading to local timezone issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Module: morebits The morebits.js library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant