Skip to content

Commit

Permalink
n with consideration of optionalDigits
Browse files Browse the repository at this point in the history
Usage of n works except when there could be optional digits, i.e. [M#1] in which case we need to also supply a lower bound of occurrences.
  • Loading branch information
JAMSUPREME authored and mattbaileyuk committed Nov 2, 2021
1 parent c16ba7b commit e6e436d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,17 @@ const dateTime = (function () {
} else { // type === 'integer'
matcher.type = 'integer';
const isUpper = formatSpec.case === tcase.UPPER;
const occurrences = formatSpec.n && formatSpec.n > 0 ? `{${formatSpec.n}}` : '+';
let occurrences;
if(formatSpec.n && formatSpec.n > 0){
if(formatSpec.optionalDigits === 0){
occurrences = `{${formatSpec.n}}`;
} else {
occurrences = `{${formatSpec.n - formatSpec.optionalDigits},${formatSpec.n}}`;
}
} else {
occurrences = '+';
}

switch (formatSpec.primary) {
case formats.LETTERS:
matcher.regex = isUpper ? '[A-Z]+' : '[a-z]+';
Expand Down

0 comments on commit e6e436d

Please sign in to comment.