@@ -612,7 +612,7 @@ const dateTime = (function () {
612
612
def . integerFormat . mandatoryDigits = def . width . min ;
613
613
}
614
614
}
615
- if ( 'YMD' . indexOf ( def . component ) !== - 1 ) {
615
+ if ( def . component === 'Y' ) {
616
616
// §9.8.4.4
617
617
def . n = - 1 ;
618
618
if ( def . width && def . width . max !== undefined ) {
@@ -625,6 +625,11 @@ const dateTime = (function () {
625
625
}
626
626
}
627
627
}
628
+ // if the previous part is also an integer with no intervening markup, then its width for parsing must be precisely defined
629
+ const previousPart = spec [ spec . length - 1 ] ;
630
+ if ( previousPart && previousPart . integerFormat ) {
631
+ previousPart . integerFormat . parseWidth = previousPart . integerFormat . mandatoryDigits ;
632
+ }
628
633
}
629
634
if ( def . component === 'Z' || def . component === 'z' ) {
630
635
def . integerFormat = analyseIntegerPicture ( def . presentation1 ) ;
@@ -990,7 +995,6 @@ const dateTime = (function () {
990
995
return offsetHours * 60 + offsetMinutes ;
991
996
} ;
992
997
} else if ( part . integerFormat ) {
993
- part . integerFormat . n = part . n ;
994
998
res = generateRegex ( part . integerFormat ) ;
995
999
} else {
996
1000
// must be a month or day name
@@ -1035,16 +1039,6 @@ const dateTime = (function () {
1035
1039
} else { // type === 'integer'
1036
1040
matcher . type = 'integer' ;
1037
1041
const isUpper = formatSpec . case === tcase . UPPER ;
1038
- let occurrences ;
1039
- if ( formatSpec . n && formatSpec . n > 0 ) {
1040
- if ( formatSpec . optionalDigits === 0 ) {
1041
- occurrences = `{${ formatSpec . n } }` ;
1042
- } else {
1043
- occurrences = `{${ formatSpec . n - formatSpec . optionalDigits } ,${ formatSpec . n } }` ;
1044
- }
1045
- } else {
1046
- occurrences = '+' ;
1047
- }
1048
1042
1049
1043
switch ( formatSpec . primary ) {
1050
1044
case formats . LETTERS :
@@ -1066,7 +1060,12 @@ const dateTime = (function () {
1066
1060
} ;
1067
1061
break ;
1068
1062
case formats . DECIMAL :
1069
- matcher . regex = `[0-9]${ occurrences } ` ;
1063
+ matcher . regex = '[0-9]' ;
1064
+ if ( formatSpec . parseWidth ) {
1065
+ matcher . regex += `{${ formatSpec . parseWidth } }` ;
1066
+ } else {
1067
+ matcher . regex += '+' ;
1068
+ }
1070
1069
if ( formatSpec . ordinal ) {
1071
1070
// ordinals
1072
1071
matcher . regex += '(?:th|st|nd|rd)' ;
0 commit comments