@@ -9,7 +9,7 @@ const matchUpperCaseAMPM = /[AP]M/
9
9
const matchLowerCaseAMPM = / [ a p ] m /
10
10
const matchSigned = / [ + - ] ? \d + / // -inf - inf
11
11
const matchOffset = / [ + - ] \d \d : ? \d \d / // +00:00 -00:00 +0000 or -0000
12
- const matchWord = / \d * [ ^ \s \d - : / . ( ) ] + / // Word
12
+ const matchWord = / \d * [ ^ \s \d - : / ( ) ] + / // Word
13
13
14
14
let locale
15
15
@@ -30,6 +30,13 @@ const zoneExpressions = [matchOffset, function (input) {
30
30
zone . offset = offsetFromString ( input )
31
31
} ]
32
32
33
+ const getLocalePart = ( name ) => {
34
+ const part = locale [ name ]
35
+ return part && (
36
+ part . indexOf ? part : part . s . concat ( part . f )
37
+ )
38
+ }
39
+
33
40
const expressions = {
34
41
A : [ matchUpperCaseAMPM , function ( input ) {
35
42
this . afternoon = input === 'PM'
@@ -69,22 +76,21 @@ const expressions = {
69
76
M : [ match1to2 , addInput ( 'month' ) ] ,
70
77
MM : [ match2 , addInput ( 'month' ) ] ,
71
78
MMM : [ matchWord , function ( input ) {
72
- const { months, monthsShort } = locale
73
- const matchIndex = monthsShort
74
- ? monthsShort . findIndex ( month => month === input )
75
- : months . findIndex ( month => month . substr ( 0 , 3 ) === input )
79
+ const months = getLocalePart ( 'months' )
80
+ const monthsShort = getLocalePart ( 'monthsShort' )
81
+ const matchIndex = ( monthsShort || months . map ( _ => _ . substr ( 0 , 3 ) ) ) . indexOf ( input )
76
82
if ( matchIndex < 0 ) {
77
83
throw new Error ( )
78
84
}
79
- this . month = matchIndex + 1
85
+ this . month = ( matchIndex + 1 ) % 12
80
86
} ] ,
81
87
MMMM : [ matchWord , function ( input ) {
82
- const { months } = locale
88
+ const months = getLocalePart ( 'months' )
83
89
const matchIndex = months . indexOf ( input )
84
90
if ( matchIndex < 0 ) {
85
91
throw new Error ( )
86
92
}
87
- this . month = matchIndex + 1
93
+ this . month = ( matchIndex + 1 ) % 12
88
94
} ] ,
89
95
Y : [ matchSigned , addInput ( 'year' ) ] ,
90
96
YY : [ match2 , function ( input ) {
0 commit comments