Repository navigation
Conversation
| ' PDT': ' -0700', | ||
| ' PST': ' -0800' | ||
| }; | ||
| var rfc2822Military = 'YXWVUTSRQPONZABCDEFGHIKLM'; |
There was a problem hiding this comment.
can you please remove rfc2822 from the names of things inside the method named configFromRFC2822 :)
|
@TracyGJG that looks pretty clean to me. Can you please summarize what is the current state, are there any places where this differs from the spec ((a) we parse it but its not spec or (b) we don't parse it but its spec), we can drop most comments and it should be good to go. |
|
@ichernev, as requested I have 'Removed rfc2822 prefix from internal variables.' in my latest commit. To answer your question regarding compliance with the spec. To be fully compliant (afaik) we have to ensure the any day given in the sting as a weekday is consistent with the date given. I have not been able to perform this check and I have disabled the test. [TODO: src/lib/create/from-string.js line 163, src/test/create.js line 448]. I had tried creating a moment from the date only elements and extract the weekday but this caused a conflict - any suggestions. |
|
@ichernev, @maggiepint and @mj1856, I finally have a fully compliant (AFAIK) implementation of RFC2822. In order to validate the weekday against the date I have had to use the native JavaScript Date object. I have left in the code a TODO to replace with an independent approach. However, as I have not managed to discover an alternative after several months, this approach will have to suffice. |
|
@TracyGJG the proper way to do the check about weekday matching is using the validation/flag system, take a look at Whether you first produce a moment object, then figure out its bad, or you first figure out its bad (by using a |
|
@ichernev, thanks for the steer. I have added the weekdayMismatch flag as suggested, defaulted to false and set to true should the check fails. I have retained setting the _isValid flag and exit (return). Is the above code appropriate or should it be simplified? |
ichernev
left a comment
There was a problem hiding this comment.
Almost ready to ship ;-)
| (\:(?:60|[0-5]\d))? | ||
| (\s(?:UT|GMT|[ECMP][SD]T|[A-IK-Z]|(?:[+-](?:1[012]|0\d)[03]0))) | ||
| $/; | ||
| */ |
There was a problem hiding this comment.
Can you please shorten this comment, remove the expanded regex, if possible just link to the source (RFC).
| ' PDT': ' -0700', | ||
| ' PST': ' -0800' | ||
| }; | ||
| var Military = 'YXWVUTSRQPONZABCDEFGHIKLM'; |
There was a problem hiding this comment.
this should be lowercase military.
| return; | ||
| } | ||
| } | ||
| getParsingFlags(config).rfc2822 = true; |
There was a problem hiding this comment.
I think we need to set this flag after a successful parse at the bottom, otherwise it might get out-of-sync
There was a problem hiding this comment.
Now that I rechecked -- the ISO parsing has the same issue. We need to set the flag only after a fully successful parse.
| configFromISO(config); | ||
| if (config._isValid === false) { | ||
| delete config._isValid; | ||
| hooks.createFromInputFallback(config); |
There was a problem hiding this comment.
this code should be linear but is instead nested. I'd return in case isValid becomes true, so more parsers can be added without increasing indentation.
| test('non RFC 2822 strings', function (assert) { | ||
| assert.ok(!moment('Tue. 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(), | ||
| 'RFC2822 datetime with all options but invalid day delimiter'); | ||
| assert.ok(!moment('Mon, 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(), |
There was a problem hiding this comment.
also check if the proper parsing flag is set.
| moment.relativeTimeThreshold('M', 11); | ||
| }); | ||
|
|
||
| /* TGJG Disabled |
There was a problem hiding this comment.
I think you need to reenable this code.
| parsedDateParts : [], | ||
| meridiem : null | ||
| meridiem : null, | ||
| rfc2822 : false, |
Test case re-enabled.
Spacing of the rfc2822 parse flag syntax aligned.
configFromString() made linear, Military variable made lowercase and RegExp comment replaced with tools.ietf reference.
Semi-colons
Trailing white-space removed
Issue with configFromString()
Made the military time zone case insensitive in line with specification.
|
Merged in 7589bb8 |
I have corrected the issue with the failing test but I still have a test I am unable to perform with out some advice. The test case 'RFC2822 datetime with mismatching Day (week v date)' confirms the day is consistent when given as both a day of week and day of month. This is a stipulation of the RFC so needs to be correct but I cannot achieve this without using a JS Date object, unless the core team have an alternative solution.
Work in Progress - Do not Merge, Advice required. Issue #2530