File tree 2 files changed +12
-6
lines changed
src/plugin/customParseFormat
2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -78,19 +78,19 @@ const expressions = {
78
78
MMM : [ matchWord , function ( input ) {
79
79
const months = getLocalePart ( 'months' )
80
80
const monthsShort = getLocalePart ( 'monthsShort' )
81
- const matchIndex = ( monthsShort || months . map ( _ => _ . substr ( 0 , 3 ) ) ) . indexOf ( input )
82
- if ( matchIndex < 0 ) {
81
+ const matchIndex = ( monthsShort || months . map ( _ => _ . substr ( 0 , 3 ) ) ) . indexOf ( input ) + 1
82
+ if ( matchIndex < 1 ) {
83
83
throw new Error ( )
84
84
}
85
- this . month = ( matchIndex + 1 ) % 12
85
+ this . month = ( matchIndex % 12 ) || matchIndex
86
86
} ] ,
87
87
MMMM : [ matchWord , function ( input ) {
88
88
const months = getLocalePart ( 'months' )
89
- const matchIndex = months . indexOf ( input )
90
- if ( matchIndex < 0 ) {
89
+ const matchIndex = months . indexOf ( input ) + 1
90
+ if ( matchIndex < 1 ) {
91
91
throw new Error ( )
92
92
}
93
- this . month = ( matchIndex + 1 ) % 12
93
+ this . month = ( matchIndex % 12 ) || matchIndex
94
94
} ] ,
95
95
Y : [ matchSigned , addInput ( 'year' ) ] ,
96
96
YY : [ match2 , function ( input ) {
Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ it('parse string for MMM month format', () => {
31
31
const input = '4/Mar/2019:11:16:26 +0800'
32
32
const format = 'D/MMM/YYYY:H:m:s zz'
33
33
expect ( dayjs ( input , format ) . valueOf ( ) ) . toBe ( moment ( input , format ) . valueOf ( ) )
34
+ const input2 = '21-Dec-18'
35
+ const format2 = 'D-MMM-YY'
36
+ expect ( dayjs ( input2 , format2 ) . valueOf ( ) ) . toBe ( moment ( input2 , format2 ) . valueOf ( ) )
34
37
} )
35
38
36
39
it ( 'parse string January (getMonth() = 0)' , ( ) => {
@@ -135,6 +138,9 @@ it('parse month from string', () => {
135
138
const input = '2018 February 03'
136
139
const format = 'YYYY MMMM DD'
137
140
expect ( dayjs ( input , format ) . valueOf ( ) ) . toBe ( moment ( input , format ) . valueOf ( ) )
141
+ const input2 = '21-December-18'
142
+ const format2 = 'D-MMMM-YY'
143
+ expect ( dayjs ( input2 , format2 ) . valueOf ( ) ) . toBe ( moment ( input2 , format2 ) . valueOf ( ) )
138
144
} )
139
145
140
146
it ( 'parse month from short string' , ( ) => {
You can’t perform that action at this time.
0 commit comments