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
[bugfix] Handle RFC2822 parsing in non-en locales, fixes #3985 #4077
Conversation
src/test/locale/ru.js
Outdated
@@ -353,3 +353,35 @@ test('weeks year starting sunday formatted', function (assert) { | |||
assert.equal(moment([2012, 0, 9]).format('w ww wo'), '3 03 3-я', 'Jan 9 2012 should be week 3'); | |||
}); | |||
|
|||
test('parsing RFC 2822', function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's confusing for this to be in the ru test file. You can test it where the rest of the RFC2822 tests are and just try/finally around moment.locale('ru')
to show that it ignores the locale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, moved it
src/lib/create/from-string.js
Outdated
}; | ||
|
||
function parse10(inty) { | ||
return parseInt(inty, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parse10
business was something dumb I did in Luxon to satisfy my linter and I already regret it. You can just replace this with parseInt(v)
everywhere and get rid of this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/lib/create/from-string.js
Outdated
|
||
function extractFromRFC2822Strings(yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) { | ||
var result = { | ||
year: yearStr.length === 2 ? untrucateYear(parse10(yearStr)) : parse10(yearStr), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be simpler to just return an array from here and then hand it directly to config._a
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, corrected it
This is looking good. I requested a few changes and you need to sign the CLA. |
src/lib/create/from-string.js
Outdated
if (match[1]) { // day of week given | ||
var momentDate = new Date(match[2]); | ||
var momentDay = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][momentDate.getDay()]; | ||
function untrucateYear(year) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moment has some specific, configurable function for this somewhere. You should use it unless the RFC spec defines this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well actually the spec says:
Where a two or three digit year occurs in a date, the year is to be
interpreted as follows: If a two digit year is encountered whose
value is between 00 and 49, the year is interpreted by adding 2000,
ending up with a value between 2000 and 2049. If a two digit year is
encountered with a value between 50 and 99, or any three digit year
is encountered, the year is interpreted by adding 1900.
In moment there's a method:
hooks.parseTwoDigitYear = function (input) {
return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
};
So 68 is hardcoded and according to spec we also have to consider 3-digit year, so I've corrected untrucateYear
to match the spec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Cannot get rid of this 'CLA not signed yet' message... I've created the pull request from a different Email and adding it to my account does not help... |
Oh I see. I bet you can fix it by rebasing your commits to have the same author. If that doesn't work, the fact is that you have signed it so we can probably move forward. |
Does this PR fix the issue that the +/-9999 is ignored and get set to GMT +0000 in the switch block, also?
|
It will get merged when we do a release. No further action is required of you. Thanks for contributing! |
@maggiepint yes. This is the fix I've implemented (but I didn't know that there was an issue or pr for that already). When this is already documented and worked on my question is answered. Thank you. |
Isn't this related to #3938 ? Or because we're not merging people keep piling the same stuff on top :) |
@@ -94,70 +97,93 @@ export function configFromISO(config) { | |||
} | |||
|
|||
// RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3 | |||
var basicRfcRegex = /^((?:Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d?\d\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(?:\d\d)?\d\d\s)(\d\d:\d\d)(\:\d\d)?(\s(?:UT|GMT|[ECMP][SD]T|[A-IK-Za-ik-z]|[+-]\d{4}))$/; | |||
var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dropped the military timezone variants from the new regex.
if (year <= 49) { | ||
return 2000 + year; | ||
} else if (year <= 999) { | ||
return 1900 + year; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this logic part of the spec? If not we need to use whatever is used in the rest of moment, and I think that part is pluggable (configurable from outside).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. See discussion in one of the collapsed-by-Github-comments above
OK, so there are 2 issues with RFC2822, one is that it doesn't handle the numeric timezone, and the other is that it fails for non en locales. We'd need to see how the merge goes, but the timezone issue is a minor one (from a code perspective), so we'll have to merge this one first. |
Merged in 0d0b291 |
[bugfix] Handle RFC2822 parsing in non-en locales, fixes #3985
[fixup] Fix RFC2822 rewrite, fixes #4077
No description provided.