@@ -156,8 +156,8 @@ class Dayjs {
156
156
startOf ( units , startOf ) { // startOf -> endOf
157
157
const isStartOf = ! Utils . isUndefined ( startOf ) ? startOf : true
158
158
const unit = Utils . prettyUnit ( units )
159
- const instanceFactory = ( d , m , y = this . $y ) => {
160
- const ins = wrapper ( new Date ( y , m , d ) , this )
159
+ const instanceFactory = ( d , m ) => {
160
+ const ins = wrapper ( new Date ( this . $ y, m , d ) , this )
161
161
return isStartOf ? ins : ins . endOf ( C . D )
162
162
}
163
163
const instanceFactorySet = ( method , slice ) => {
@@ -171,13 +171,13 @@ class Dayjs {
171
171
switch ( unit ) {
172
172
case C . Y :
173
173
return isStartOf ? instanceFactory ( 1 , 0 ) :
174
- instanceFactory ( 31 , 11 , this . $y )
174
+ instanceFactory ( 31 , 11 )
175
175
case C . M :
176
176
return isStartOf ? instanceFactory ( 1 , this . $M ) :
177
- instanceFactory ( 0 , this . $M + 1 , this . $y )
177
+ instanceFactory ( 0 , this . $M + 1 )
178
178
case C . W :
179
179
return isStartOf ? instanceFactory ( this . $D - this . $W , this . $M ) :
180
- instanceFactory ( this . $D + ( 6 - this . $W ) , this . $M , this . $y )
180
+ instanceFactory ( this . $D + ( 6 - this . $W ) , this . $M )
181
181
case C . D :
182
182
case C . DATE :
183
183
return instanceFactorySet ( 'setHours' , 0 )
@@ -234,37 +234,31 @@ class Dayjs {
234
234
235
235
add ( number , units ) {
236
236
number = Number ( number ) // eslint-disable-line no-param-reassign
237
- // units === 'ms' hard code here, will update in next release
238
- const unit = ( units && ( units . length === 1 || units === 'ms' ) ) ? units : Utils . prettyUnit ( units )
237
+ const unit = Utils . prettyUnit ( units )
239
238
const instanceFactory = ( u , n ) => {
240
239
const date = this . set ( C . DATE , 1 ) . set ( u , n + number )
241
240
return date . set ( C . DATE , Math . min ( this . $D , date . daysInMonth ( ) ) )
242
241
}
243
- if ( [ 'M' , C . M ] . indexOf ( unit ) > - 1 ) {
242
+ if ( unit === C . M ) {
244
243
return instanceFactory ( C . M , this . $M )
245
244
}
246
- if ( [ 'y' , C . Y ] . indexOf ( unit ) > - 1 ) {
245
+ if ( unit === C . Y ) {
247
246
return instanceFactory ( C . Y , this . $y )
248
247
}
249
248
let step
250
249
switch ( unit ) {
251
- case 'm' :
252
250
case C . MIN :
253
251
step = C . MILLISECONDS_A_MINUTE
254
252
break
255
- case 'h' :
256
253
case C . H :
257
254
step = C . MILLISECONDS_A_HOUR
258
255
break
259
- case 'd' :
260
256
case C . D :
261
257
step = C . MILLISECONDS_A_DAY
262
258
break
263
- case 'w' :
264
259
case C . W :
265
260
step = C . MILLISECONDS_A_WEEK
266
261
break
267
- case 's' :
268
262
case C . S :
269
263
step = C . MILLISECONDS_A_SECOND
270
264
break
0 commit comments