11import { u } from '../localizedFormat/utils'
22
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
44
55const match1 = / \d / // 0 - 9
66const match2 = / \d \d / // 00 - 99
@@ -66,6 +66,9 @@ const expressions = {
6666 a : [ matchWord , function ( input ) {
6767 this . afternoon = meridiemMatch ( input , true )
6868 } ] ,
69+ Q : [ match1 , function ( input ) {
70+ this . month = ( ( input - 1 ) * 3 ) + 1
71+ } ] ,
6972 S : [ match1 , function ( input ) {
7073 this . milliseconds = + input * 100
7174 } ] ,
@@ -95,6 +98,8 @@ const expressions = {
9598 }
9699 }
97100 } ] ,
101+ w : [ match1to2 , addInput ( 'week' ) ] ,
102+ ww : [ match2 , addInput ( 'week' ) ] ,
98103 M : [ match1to2 , addInput ( 'month' ) ] ,
99104 MM : [ match2 , addInput ( 'month' ) ] ,
100105 MMM : [ matchWord , function ( input ) {
@@ -173,12 +178,12 @@ function makeParser(format) {
173178 }
174179}
175180
176- const parseFormattedInput = ( input , format , utc ) => {
181+ const parseFormattedInput = ( input , format , utc , dayjs ) => {
177182 try {
178183 if ( [ 'x' , 'X' ] . indexOf ( format ) > - 1 ) return new Date ( ( format === 'X' ? 1000 : 1 ) * input )
179184 const parser = makeParser ( format )
180185 const {
181- year, month, day, hours, minutes, seconds, milliseconds, zone
186+ year, month, day, hours, minutes, seconds, milliseconds, zone, week
182187 } = parser ( input )
183188 const now = new Date ( )
184189 const d = day || ( ( ! year && ! month ) ? now . getDate ( ) : 1 )
@@ -197,7 +202,12 @@ const parseFormattedInput = (input, format, utc) => {
197202 if ( utc ) {
198203 return new Date ( Date . UTC ( y , M , d , h , m , s , ms ) )
199204 }
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
201211 } catch ( e ) {
202212 return new Date ( '' ) // Invalid Date
203213 }
@@ -224,12 +234,12 @@ export default (o, C, d) => {
224234 const isStrictWithLocale = args [ 3 ] === true
225235 const isStrict = isStrictWithoutLocale || isStrictWithLocale
226236 let pl = args [ 2 ]
227- if ( isStrictWithLocale ) [ , , pl ] = args
237+ if ( isStrictWithLocale ) [ , , pl ] = args
228238 locale = this . $locale ( )
229239 if ( ! isStrictWithoutLocale && pl ) {
230240 locale = d . Ls [ pl ]
231241 }
232- this . $d = parseFormattedInput ( date , format , utc )
242+ this . $d = parseFormattedInput ( date , format , utc , d )
233243 this . init ( )
234244 if ( pl && pl !== true ) this . $L = this . locale ( pl ) . $L
235245 // use != to treat
0 commit comments