From 47b9f38e4d733ecd27ea2774ef18f6c3ae74c2d9 Mon Sep 17 00:00:00 2001 From: Deniss Kozickis Date: Thu, 9 Apr 2020 17:45:37 +0300 Subject: [PATCH] Fix quarters parsing (closes #1650) The locale was parsing wrong string after matching the pattern --- src/locale/_lib/buildMatchFn/index.js | 4 ++-- src/parse/test.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/locale/_lib/buildMatchFn/index.js b/src/locale/_lib/buildMatchFn/index.js index 2bf1c88e14..a5bd529807 100644 --- a/src/locale/_lib/buildMatchFn/index.js +++ b/src/locale/_lib/buildMatchFn/index.js @@ -21,11 +21,11 @@ export default function buildMatchFn(args) { var value if (Object.prototype.toString.call(parsePatterns) === '[object Array]') { value = findIndex(parsePatterns, function(pattern) { - return pattern.test(string) + return pattern.test(matchedString) }) } else { value = findKey(parsePatterns, function(pattern) { - return pattern.test(string) + return pattern.test(matchedString) }) } diff --git a/src/parse/test.js b/src/parse/test.js index 14e33adc19..fdcdb7dab8 100644 --- a/src/parse/test.js +++ b/src/parse/test.js @@ -387,6 +387,28 @@ describe('parse', function() { }) }) + describe('quarter with following year', function() { + it('first quarter', function() { + var result = parse('Q1/2020', 'QQQ/yyyy', referenceDate) + assert.deepEqual(result, new Date(2020, 0 /* Jan */, 1)) + }) + + it('second quarter', function() { + var result = parse('Q2/2020', 'QQQ/yyyy', referenceDate) + assert.deepEqual(result, new Date(2020, 3 /* Apr */, 1)) + }) + + it('third quarter', function() { + var result = parse('Q3/2020', 'QQQ/yyyy', referenceDate) + assert.deepEqual(result, new Date(2020, 6 /* Jul */, 1)) + }) + + it('fourth quarter', function() { + var result = parse('Q4/2020', 'QQQ/yyyy', referenceDate) + assert.deepEqual(result, new Date(2020, 9 /* Oct */, 1)) + }) + }) + describe('quarter (formatting)', function() { it('numeric', function() { var result = parse('1', 'Q', referenceDate)