]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Trial day-of-week validation using a vanilla Date object.
authorTGJG-XPS\TracyG <tracyg.gilmore@gmail.com>
Mon, 13 Feb 2017 20:19:41 +0000 (20:19 +0000)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 12 Mar 2017 00:11:46 +0000 (02:11 +0200)
src/lib/create/from-string.js
src/test/moment/create.js

index 429863461e931a350a20d6777081c4841d54f8c7..44898d33c81db4f29399452059f113dabc668fac 100644 (file)
@@ -162,17 +162,18 @@ export function configFromRFC2822(config) {
 
         // TODO Confirm the given day-of-week is consistent with the day-of-month-year
         //  NB: Needs an instance of moment, created from the date element of the input string.
-        /*
+        /* */
         if (match[1]) { // day of week given
-            console.log('[' + match[1].substr(0,3) + ']', moment(match[2], dateFormat).format('ddd'));
-            var momentDay = moment(match[2], dateFormat).format('ddd');
+//            console.log('[' + match[1].substr(0,3) + ']', moment(match[2], dateFormat).format('ddd'));
+            var momentDate = new Date(match[2]);
+            var momentDay = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][momentDate.getDay()];
 
             if (match[1].substr(0,3) !== momentDay) {
                 config._isValid = false;
                 return;
             }
         }
-        */
+        /* */
         getParsingFlags(config).rfc2822 = true;
 
         switch (match[5].length) {
index 65217b37e3fa01255da8a4b25184a042fb7e5fe5..408432e47da9875cbc404303bb2ce558ebe9e9a9 100644 (file)
@@ -477,8 +477,11 @@ 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');
     /* TODO Confirm the given day-of-week is consistent with the day-of-month-year
+     * 
+     */
     assert.ok(!moment('Mon, 01 Nov 2016 01:23:45 GMT', moment.RFC_2822, true).isValid(),
         'RFC2822 datetime with mismatching Day (week v date)');
+    /*
     */
 });