1
1
import { u } from '../localizedFormat/utils'
2
2
3
- const formattingTokens = / ( \[ [ ^ [ ] * \] ) | ( [ - _ : / . , ( ) \s ] + ) | ( A | a | Y Y Y Y | Y Y ? | M M ? M ? M ? | D o | D D ? | h h ? | H H ? | m m ? | s s ? | S { 1 , 3 } | z | Z Z ? ) / g
3
+ const formattingTokens = / ( \[ [ ^ [ ] * \] ) | ( [ - _ : / . , ( ) \s ] + ) | ( A | a | Q | Y Y Y Y | Y Y ? | w w ? | M M ? M ? M ? | D o | D D ? | h h ? | H H ? | m m ? | s s ? | S { 1 , 3 } | z | Z Z ? ) / g
4
4
5
5
const match1 = / \d / // 0 - 9
6
6
const match2 = / \d \d / // 00 - 99
@@ -66,6 +66,9 @@ const expressions = {
66
66
a : [ matchWord , function ( input ) {
67
67
this . afternoon = meridiemMatch ( input , true )
68
68
} ] ,
69
+ Q : [ match1 , function ( input ) {
70
+ this . month = ( ( input - 1 ) * 3 ) + 1
71
+ } ] ,
69
72
S : [ match1 , function ( input ) {
70
73
this . milliseconds = + input * 100
71
74
} ] ,
@@ -95,6 +98,8 @@ const expressions = {
95
98
}
96
99
}
97
100
} ] ,
101
+ w : [ match1to2 , addInput ( 'week' ) ] ,
102
+ ww : [ match2 , addInput ( 'week' ) ] ,
98
103
M : [ match1to2 , addInput ( 'month' ) ] ,
99
104
MM : [ match2 , addInput ( 'month' ) ] ,
100
105
MMM : [ matchWord , function ( input ) {
@@ -173,12 +178,12 @@ function makeParser(format) {
173
178
}
174
179
}
175
180
176
- const parseFormattedInput = ( input , format , utc ) => {
181
+ const parseFormattedInput = ( input , format , utc , dayjs ) => {
177
182
try {
178
183
if ( [ 'x' , 'X' ] . indexOf ( format ) > - 1 ) return new Date ( ( format === 'X' ? 1000 : 1 ) * input )
179
184
const parser = makeParser ( format )
180
185
const {
181
- year, month, day, hours, minutes, seconds, milliseconds, zone
186
+ year, month, day, hours, minutes, seconds, milliseconds, zone, week
182
187
} = parser ( input )
183
188
const now = new Date ( )
184
189
const d = day || ( ( ! year && ! month ) ? now . getDate ( ) : 1 )
@@ -197,7 +202,12 @@ const parseFormattedInput = (input, format, utc) => {
197
202
if ( utc ) {
198
203
return new Date ( Date . UTC ( y , M , d , h , m , s , ms ) )
199
204
}
200
- return new Date ( y , M , d , h , m , s , ms )
205
+ let newDate
206
+ newDate = new Date ( y , M , d , h , m , s , ms )
207
+ if ( week ) {
208
+ newDate = dayjs ( newDate ) . week ( week ) . toDate ( )
209
+ }
210
+ return newDate
201
211
} catch ( e ) {
202
212
return new Date ( '' ) // Invalid Date
203
213
}
@@ -224,12 +234,12 @@ export default (o, C, d) => {
224
234
const isStrictWithLocale = args [ 3 ] === true
225
235
const isStrict = isStrictWithoutLocale || isStrictWithLocale
226
236
let pl = args [ 2 ]
227
- if ( isStrictWithLocale ) [ , , pl ] = args
237
+ if ( isStrictWithLocale ) [ , , pl ] = args
228
238
locale = this . $locale ( )
229
239
if ( ! isStrictWithoutLocale && pl ) {
230
240
locale = d . Ls [ pl ]
231
241
}
232
- this . $d = parseFormattedInput ( date , format , utc )
242
+ this . $d = parseFormattedInput ( date , format , utc , d )
233
243
this . init ( )
234
244
if ( pl && pl !== true ) this . $L = this . locale ( pl ) . $L
235
245
// use != to treat
0 commit comments