]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Treat periods as periods, not regex-anything period, for weekday parsing...
authorCaleb Cauthon <calebcauthon@users.noreply.github.com>
Sun, 15 Apr 2018 06:09:18 +0000 (01:09 -0500)
committerKunal Marwaha <marwahaha@berkeley.edu>
Sun, 15 Apr 2018 06:09:18 +0000 (22:09 -0800)
* Treat periods in short weekdays as literal periods when in strict mode with exact parsing turned off

* Add tests for the other 2 areas where periods were treated improperly, and organize the tests

* Remove trailing commas

* Follow styling standards

src/lib/units/day-of-week.js
src/test/moment/locale.js

index 55027608d189a48d613ea2f71f1ef42c789ac842..438160b870d79379b474795a5f2bb1df53b3117c 100644 (file)
@@ -200,9 +200,9 @@ export function localeWeekdaysParse (weekdayName, format, strict) {
 
         mom = createUTC([2000, 1]).day(i);
         if (strict && !this._fullWeekdaysParse[i]) {
-            this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\.?') + '$', 'i');
-            this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\.?') + '$', 'i');
-            this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\.?') + '$', 'i');
+            this._fullWeekdaysParse[i] = new RegExp('^' + this.weekdays(mom, '').replace('.', '\\.?') + '$', 'i');
+            this._shortWeekdaysParse[i] = new RegExp('^' + this.weekdaysShort(mom, '').replace('.', '\\.?') + '$', 'i');
+            this._minWeekdaysParse[i] = new RegExp('^' + this.weekdaysMin(mom, '').replace('.', '\\.?') + '$', 'i');
         }
         if (!this._weekdaysParse[i]) {
             regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');
index 186c649dfe2f1163874c08a6b11abdec6d051fe5..adebfaee30d83178504b2ae717bb02af8e01c60a 100644 (file)
@@ -471,6 +471,39 @@ test('moment().lang with missing key doesn\'t change locale', function (assert)
             'preserve global locale in case of bad locale id');
 });
 
+test('when in strict mode with inexact parsing, treat periods in short weekdays literally, not as the regex-period', function (assert) {
+    moment.defineLocale('periods-in-short-weekdays', {
+        weekdays : 'Monday_Tuesday_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
+        weekdaysShort : 'mon_t...s_wed_thurs_fri_sat_sun'.split('_'),
+        weekdaysParseExact : false
+    });
+
+    moment().locale('periods-in-short-weekdays');
+    assert.equal(moment('thurs', 'ddd', true).format('dddd'), 'Thursday');
+});
+
+test('when in strict mode with inexact parsing, treat periods in full weekdays literally, not as the regex-period', function (assert) {
+    moment.defineLocale('periods-in-full-weekdays', {
+        weekdays : 'Monday_T....day_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
+        weekdaysShort : 'mon_tues_wed_thurs_fri_sat_sun'.split('_'),
+        weekdaysParseExact : false
+    });
+
+    moment().locale('periods-in-full-weekdays');
+    assert.equal(moment('Thursday', 'dddd', true).format('ddd'), 'thurs');
+});
+
+test('when in strict mode with inexact parsing, treat periods in min-weekdays literally, not as the regex-period', function (assert) {
+    moment.defineLocale('periods-in-min-weekdays', {
+        weekdays : 'Monday_Tuesday_Wednesday_Thursday_Friday_Saturday_Sunday'.split('_'),
+        weekdaysMin : 'mon_t...s_wed_thurs_fri_sat_sun'.split('_'),
+        weekdaysParseExact : false
+    });
+
+    moment().locale('periods-in-min-weekdays');
+    assert.equal(moment('thurs', 'dd', true).format('dddd'), 'Thursday');
+});
+
 
 // TODO: Enable this after fixing pl months parse hack hack
 // test('monthsParseExact', function (assert) {