Skip to content

Commit e6e436d

Browse files
JAMSUPREMEmattbaileyuk
authored andcommittedNov 2, 2021
n with consideration of optionalDigits
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.
1 parent c16ba7b commit e6e436d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
 

‎src/datetime.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,17 @@ const dateTime = (function () {
10281028
} else { // type === 'integer'
10291029
matcher.type = 'integer';
10301030
const isUpper = formatSpec.case === tcase.UPPER;
1031-
const occurrences = formatSpec.n && formatSpec.n > 0 ? `{${formatSpec.n}}` : '+';
1031+
let occurrences;
1032+
if(formatSpec.n && formatSpec.n > 0){
1033+
if(formatSpec.optionalDigits === 0){
1034+
occurrences = `{${formatSpec.n}}`;
1035+
} else {
1036+
occurrences = `{${formatSpec.n - formatSpec.optionalDigits},${formatSpec.n}}`;
1037+
}
1038+
} else {
1039+
occurrences = '+';
1040+
}
1041+
10321042
switch (formatSpec.primary) {
10331043
case formats.LETTERS:
10341044
matcher.regex = isUpper ? '[A-Z]+' : '[a-z]+';

0 commit comments

Comments
 (0)
Please sign in to comment.