Skip to content

Commit

Permalink
Fix quarters parsing (closes #1650)
Browse files Browse the repository at this point in the history
The locale was parsing wrong string after matching the pattern
  • Loading branch information
dkozickis committed Apr 9, 2020
1 parent c531935 commit 47b9f38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/locale/_lib/buildMatchFn/index.js
Expand Up @@ -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)
})
}

Expand Down
22 changes: 22 additions & 0 deletions src/parse/test.js
Expand Up @@ -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)
Expand Down

0 comments on commit 47b9f38

Please sign in to comment.