16
16
17
17
define ( [
18
18
'jquery' ,
19
- 'jquery-ui-modules/datepicker' ,
19
+ 'jquery-ui-modules/datepicker'
20
20
] , function ( $ ) {
21
21
'use strict' ;
22
22
@@ -31,24 +31,24 @@ define([
31
31
* @private
32
32
*/
33
33
$ . 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' ;
36
36
}
37
37
38
- value = ( typeof value === " object" ? value . toString ( ) : value + "" ) ;
39
- if ( value === "" ) {
38
+ value = typeof value === ' object' ? value . toString ( ) : value + '' ;
39
+ if ( value === '' ) {
40
40
return null ;
41
41
}
42
42
43
- var iFormat , dim , extra ,
43
+ let iFormat , dim , extra ,
44
44
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 ,
52
52
year = - 1 ,
53
53
month = - 1 ,
54
54
day = - 1 ,
@@ -57,143 +57,149 @@ define([
57
57
date ,
58
58
59
59
// 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 ) {
63
64
iFormat ++ ;
64
65
}
65
66
return matches ;
66
67
} ,
67
68
68
69
// 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 ,
73
74
// v1.9.2 RegExp to fix selection of dates
74
75
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 ;
78
80
}
79
- iValue += num [ 0 ] . length ;
80
- return parseInt ( num [ 0 ] , 10 ) ;
81
+ iValue += num [ 0 ] . length ;
82
+ return parseInt ( num [ 0 ] , 10 ) ;
81
83
} ,
82
84
83
85
// Extract a name from the string value and convert to an index
84
- getName = function ( match , shortNames , longNames ) {
86
+ getName = function ( match , shortNames , longNames ) {
85
87
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 ] ;
96
99
iValue += name . length ;
97
100
return false ;
98
101
}
99
- } ) ;
100
- if ( index !== - 1 ) {
102
+ } ) ;
103
+ if ( index !== - 1 ) {
101
104
return index + 1 ;
102
- } else {
103
- throw "Unknown name at position " + iValue ;
104
105
}
106
+ throw 'Unknown name at position ' + iValue ;
105
107
} ,
106
108
107
109
// Confirm that a literal character matches the string value
108
110
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 ;
111
113
}
112
114
iValue ++ ;
113
115
} ;
114
116
115
117
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 ( '\'' ) ) {
118
121
literal = false ;
119
122
} else {
120
123
checkLiteral ( ) ;
121
124
}
122
125
} 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 ( '\'' ) ) {
162
161
checkLiteral ( ) ;
162
+ } else {
163
+ literal = true ;
164
+ }
165
+ break ;
166
+ default :
167
+ checkLiteral ( ) ;
163
168
}
164
169
}
165
170
}
166
171
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 ;
171
176
}
172
177
}
173
178
174
- if ( year === - 1 ) {
179
+ if ( year === - 1 ) {
175
180
year = new Date ( ) . getFullYear ( ) ;
176
- } else if ( year < 100 ) {
181
+ } else if ( year < 100 ) {
177
182
year += new Date ( ) . getFullYear ( ) - new Date ( ) . getFullYear ( ) % 100 +
178
- ( year <= shortYearCutoff ? 0 : - 100 ) ;
183
+ ( year <= shortYearCutoff ? 0 : - 100 ) ;
179
184
}
180
185
181
- if ( doy > - 1 ) {
186
+ if ( doy > - 1 ) {
182
187
month = 1 ;
183
188
day = doy ;
184
189
do {
185
- dim = this . _getDaysInMonth ( year , month - 1 ) ;
186
- if ( day <= dim ) {
190
+ dim = this . _getDaysInMonth ( year , month - 1 ) ;
191
+ if ( day <= dim ) {
187
192
break ;
188
193
}
189
194
month ++ ;
190
195
day -= dim ;
191
- } while ( true ) ;
196
+ // eslint-disable-next-line no-constant-condition
197
+ } while ( true ) ;
192
198
}
193
199
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
197
203
}
198
204
return date ;
199
205
} ;
0 commit comments