1616
1717define ( [
1818 'jquery' ,
19- 'jquery-ui-modules/datepicker' ,
19+ 'jquery-ui-modules/datepicker'
2020] , function ( $ ) {
2121 'use strict' ;
2222
@@ -31,24 +31,24 @@ define([
3131 * @private
3232 */
3333 $ . datepicker . parseDate = function ( format , value , settings ) {
34- if ( format == null || value == null ) {
35- throw " Invalid arguments" ;
34+ if ( format == null || value == null ) {
35+ throw ' Invalid arguments' ;
3636 }
3737
38- value = ( typeof value === " object" ? value . toString ( ) : value + "" ) ;
39- if ( value === "" ) {
38+ value = typeof value === ' object' ? value . toString ( ) : value + '' ;
39+ if ( value === '' ) {
4040 return null ;
4141 }
4242
43- var iFormat , dim , extra ,
43+ let iFormat , dim , extra ,
4444 iValue = 0 ,
45- shortYearCutoffTemp = ( settings ? settings . shortYearCutoff : null ) || this . _defaults . shortYearCutoff ,
46- shortYearCutoff = ( typeof shortYearCutoffTemp !== " string" ? shortYearCutoffTemp :
47- new Date ( ) . getFullYear ( ) % 100 + parseInt ( shortYearCutoffTemp , 10 ) ) ,
48- dayNamesShort = ( settings ? settings . dayNamesShort : null ) || this . _defaults . dayNamesShort ,
49- dayNames = ( settings ? settings . dayNames : null ) || this . _defaults . dayNames ,
50- monthNamesShort = ( settings ? settings . monthNamesShort : null ) || this . _defaults . monthNamesShort ,
51- monthNames = ( settings ? settings . monthNames : null ) || this . _defaults . monthNames ,
45+ shortYearCutoffTemp = ( settings ? settings . shortYearCutoff : null ) || this . _defaults . shortYearCutoff ,
46+ shortYearCutoff = typeof shortYearCutoffTemp !== ' string' ? shortYearCutoffTemp :
47+ new Date ( ) . getFullYear ( ) % 100 + parseInt ( shortYearCutoffTemp , 10 ) ,
48+ dayNamesShort = ( settings ? settings . dayNamesShort : null ) || this . _defaults . dayNamesShort ,
49+ dayNames = ( settings ? settings . dayNames : null ) || this . _defaults . dayNames ,
50+ monthNamesShort = ( settings ? settings . monthNamesShort : null ) || this . _defaults . monthNamesShort ,
51+ monthNames = ( settings ? settings . monthNames : null ) || this . _defaults . monthNames ,
5252 year = - 1 ,
5353 month = - 1 ,
5454 day = - 1 ,
@@ -57,143 +57,149 @@ define([
5757 date ,
5858
5959 // Check whether a format character is doubled
60- lookAhead = function ( match ) {
61- var matches = ( iFormat + 1 < format . length && format . charAt ( iFormat + 1 ) === match ) ;
62- if ( matches ) {
60+ lookAhead = function ( match ) {
61+ const matches = iFormat + 1 < format . length && format . charAt ( iFormat + 1 ) === match ;
62+
63+ if ( matches ) {
6364 iFormat ++ ;
6465 }
6566 return matches ;
6667 } ,
6768
6869 // Extract a number from the string value
69- getNumber = function ( match ) {
70- var isDoubled = lookAhead ( match ) ,
71- size = ( match === "@" ? 14 : ( match === "!" ? 20 :
72- ( match === "y" && isDoubled ? 4 : ( match === "o" ? 3 : 2 ) ) ) ) ,
70+ getNumber = function ( match ) {
71+ const isDoubled = lookAhead ( match ) ,
72+ size = match === '@' ? 14 : match === '!' ? 20 :
73+ match === 'y' && isDoubled ? 4 : match === 'o' ? 3 : 2 ,
7374 // v1.9.2 RegExp to fix selection of dates
7475 digits = new RegExp ( '^\\d{1,' + size + '}' ) ,
75- num = value . substring ( iValue ) . match ( digits ) ;
76- if ( ! num ) {
77- throw "Missing number at position " + iValue ;
76+ num = value . substring ( iValue ) . match ( digits ) ;
77+
78+ if ( ! num ) {
79+ throw 'Missing number at position ' + iValue ;
7880 }
79- iValue += num [ 0 ] . length ;
80- return parseInt ( num [ 0 ] , 10 ) ;
81+ iValue += num [ 0 ] . length ;
82+ return parseInt ( num [ 0 ] , 10 ) ;
8183 } ,
8284
8385 // Extract a name from the string value and convert to an index
84- getName = function ( match , shortNames , longNames ) {
86+ getName = function ( match , shortNames , longNames ) {
8587 var index = - 1 ,
86- names = $ . map ( lookAhead ( match ) ? longNames : shortNames , function ( v , k ) {
87- return [ [ k , v ] ] ;
88- } ) . sort ( function ( a , b ) {
89- return - ( a [ 1 ] . length - b [ 1 ] . length ) ;
90- } ) ;
91-
92- $ . each ( names , function ( i , pair ) {
93- var name = pair [ 1 ] ;
94- if ( value . substr ( iValue , name . length ) . toLowerCase ( ) === name . toLowerCase ( ) ) {
95- index = pair [ 0 ] ;
88+ names = $ . map ( lookAhead ( match ) ? longNames : shortNames , function ( v , k ) {
89+ return [ [ k , v ] ] ;
90+ } ) . sort ( function ( a , b ) {
91+ return - ( a [ 1 ] . length - b [ 1 ] . length ) ;
92+ } ) ;
93+
94+ $ . each ( names , function ( i , pair ) {
95+ const name = pair [ 1 ] ;
96+
97+ if ( value . substr ( iValue , name . length ) . toLowerCase ( ) === name . toLowerCase ( ) ) {
98+ index = pair [ 0 ] ;
9699 iValue += name . length ;
97100 return false ;
98101 }
99- } ) ;
100- if ( index !== - 1 ) {
102+ } ) ;
103+ if ( index !== - 1 ) {
101104 return index + 1 ;
102- } else {
103- throw "Unknown name at position " + iValue ;
104105 }
106+ throw 'Unknown name at position ' + iValue ;
105107 } ,
106108
107109 // Confirm that a literal character matches the string value
108110 checkLiteral = function ( ) {
109- if ( value . charAt ( iValue ) !== format . charAt ( iFormat ) ) {
110- throw " Unexpected literal at position " + iValue ;
111+ if ( value . charAt ( iValue ) !== format . charAt ( iFormat ) ) {
112+ throw ' Unexpected literal at position ' + iValue ;
111113 }
112114 iValue ++ ;
113115 } ;
114116
115117 for ( iFormat = 0 ; iFormat < format . length ; iFormat ++ ) {
116- if ( literal ) {
117- if ( format . charAt ( iFormat ) === "'" && ! lookAhead ( "'" ) ) {
118+ if ( literal ) {
119+ // eslint-disable-next-line max-depth
120+ if ( format . charAt ( iFormat ) === '\'' && ! lookAhead ( '\'' ) ) {
118121 literal = false ;
119122 } else {
120123 checkLiteral ( ) ;
121124 }
122125 } else {
123- switch ( format . charAt ( iFormat ) ) {
124- case "d" :
125- day = getNumber ( "d" ) ;
126- break ;
127- case "D" :
128- getName ( "D" , dayNamesShort , dayNames ) ;
129- break ;
130- case "o" :
131- doy = getNumber ( "o" ) ;
132- break ;
133- case "m" :
134- month = getNumber ( "m" ) ;
135- break ;
136- case "M" :
137- month = getName ( "M" , monthNamesShort , monthNames ) ;
138- break ;
139- case "y" :
140- year = getNumber ( "y" ) ;
141- break ;
142- case "@" :
143- date = new Date ( getNumber ( "@" ) ) ;
144- year = date . getFullYear ( ) ;
145- month = date . getMonth ( ) + 1 ;
146- day = date . getDate ( ) ;
147- break ;
148- case "!" :
149- date = new Date ( ( getNumber ( "!" ) - this . _ticksTo1970 ) / 10000 ) ;
150- year = date . getFullYear ( ) ;
151- month = date . getMonth ( ) + 1 ;
152- day = date . getDate ( ) ;
153- break ;
154- case "'" :
155- if ( lookAhead ( "'" ) ) {
156- checkLiteral ( ) ;
157- } else {
158- literal = true ;
159- }
160- break ;
161- default :
126+ // eslint-disable-next-line max-depth
127+ switch ( format . charAt ( iFormat ) ) {
128+ case 'd' :
129+ day = getNumber ( 'd' ) ;
130+ break ;
131+ case 'D' :
132+ getName ( 'D' , dayNamesShort , dayNames ) ;
133+ break ;
134+ case 'o' :
135+ doy = getNumber ( 'o' ) ;
136+ break ;
137+ case 'm' :
138+ month = getNumber ( 'm' ) ;
139+ break ;
140+ case 'M' :
141+ month = getName ( 'M' , monthNamesShort , monthNames ) ;
142+ break ;
143+ case 'y' :
144+ year = getNumber ( 'y' ) ;
145+ break ;
146+ case '@' :
147+ date = new Date ( getNumber ( '@' ) ) ;
148+ year = date . getFullYear ( ) ;
149+ month = date . getMonth ( ) + 1 ;
150+ day = date . getDate ( ) ;
151+ break ;
152+ case '!' :
153+ date = new Date ( ( getNumber ( '!' ) - this . _ticksTo1970 ) / 10000 ) ;
154+ year = date . getFullYear ( ) ;
155+ month = date . getMonth ( ) + 1 ;
156+ day = date . getDate ( ) ;
157+ break ;
158+ case '\'' :
159+ // eslint-disable-next-line max-depth
160+ if ( lookAhead ( '\'' ) ) {
162161 checkLiteral ( ) ;
162+ } else {
163+ literal = true ;
164+ }
165+ break ;
166+ default :
167+ checkLiteral ( ) ;
163168 }
164169 }
165170 }
166171
167- if ( iValue < value . length ) {
168- extra = value . substr ( iValue ) ;
169- if ( ! / ^ \s + / . test ( extra ) ) {
170- throw " Extra/unparsed characters found in date: " + extra ;
172+ if ( iValue < value . length ) {
173+ extra = value . substr ( iValue ) ;
174+ if ( ! / ^ \s + / . test ( extra ) ) {
175+ throw ' Extra/unparsed characters found in date: ' + extra ;
171176 }
172177 }
173178
174- if ( year === - 1 ) {
179+ if ( year === - 1 ) {
175180 year = new Date ( ) . getFullYear ( ) ;
176- } else if ( year < 100 ) {
181+ } else if ( year < 100 ) {
177182 year += new Date ( ) . getFullYear ( ) - new Date ( ) . getFullYear ( ) % 100 +
178- ( year <= shortYearCutoff ? 0 : - 100 ) ;
183+ ( year <= shortYearCutoff ? 0 : - 100 ) ;
179184 }
180185
181- if ( doy > - 1 ) {
186+ if ( doy > - 1 ) {
182187 month = 1 ;
183188 day = doy ;
184189 do {
185- dim = this . _getDaysInMonth ( year , month - 1 ) ;
186- if ( day <= dim ) {
190+ dim = this . _getDaysInMonth ( year , month - 1 ) ;
191+ if ( day <= dim ) {
187192 break ;
188193 }
189194 month ++ ;
190195 day -= dim ;
191- } while ( true ) ;
196+ // eslint-disable-next-line no-constant-condition
197+ } while ( true ) ;
192198 }
193199
194- date = this . _daylightSavingAdjust ( new Date ( year , month - 1 , day ) ) ;
195- if ( date . getFullYear ( ) !== year || date . getMonth ( ) + 1 !== month || date . getDate ( ) !== day ) {
196- throw " Invalid date" ; // E.g. 31/02/00
200+ date = this . _daylightSavingAdjust ( new Date ( year , month - 1 , day ) ) ;
201+ if ( date . getFullYear ( ) !== year || date . getMonth ( ) + 1 !== month || date . getDate ( ) !== day ) {
202+ throw ' Invalid date' ; // E.g. 31/02/00
197203 }
198204 return date ;
199205 } ;
0 commit comments