File tree Expand file tree Collapse file tree 2 files changed +33
-12
lines changed Expand file tree Collapse file tree 2 files changed +33
-12
lines changed Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ root = true
44charset = utf-8
55end_of_line = lf
66insert_final_newline = true
7+ indent_size = 2
Original file line number Diff line number Diff line change @@ -319,18 +319,38 @@ class Dayjs {
319319 const that = dayjs ( input )
320320 const zoneDelta = ( that . utcOffset ( ) - this . utcOffset ( ) ) * C . MILLISECONDS_A_MINUTE
321321 const diff = this - that
322- let result = Utils . m ( this , that )
323-
324- result = {
325- [ C . Y ] : result / 12 ,
326- [ C . M ] : result ,
327- [ C . Q ] : result / 3 ,
328- [ C . W ] : ( diff - zoneDelta ) / C . MILLISECONDS_A_WEEK ,
329- [ C . D ] : ( diff - zoneDelta ) / C . MILLISECONDS_A_DAY ,
330- [ C . H ] : diff / C . MILLISECONDS_A_HOUR ,
331- [ C . MIN ] : diff / C . MILLISECONDS_A_MINUTE ,
332- [ C . S ] : diff / C . MILLISECONDS_A_SECOND
333- } [ unit ] || diff // milliseconds
322+ const getMonth = ( ) => Utils . m ( this , that )
323+
324+ let result
325+ switch ( unit ) {
326+ case C . Y :
327+ result = getMonth ( ) / 12
328+ break
329+ case C . M :
330+ result = getMonth ( )
331+ break
332+ case C . Q :
333+ result = getMonth ( ) / 3
334+ break
335+ case C . W :
336+ result = ( diff - zoneDelta ) / C . MILLISECONDS_A_WEEK
337+ break
338+ case C . D :
339+ result = ( diff - zoneDelta ) / C . MILLISECONDS_A_DAY
340+ break
341+ case C . H :
342+ result = diff / C . MILLISECONDS_A_HOUR
343+ break
344+ case C . MIN :
345+ result = diff / C . MILLISECONDS_A_MINUTE
346+ break
347+ case C . S :
348+ result = diff / C . MILLISECONDS_A_SECOND
349+ break
350+ default :
351+ result = diff // milliseconds
352+ break
353+ }
334354
335355 return float ? result : Utils . a ( result )
336356 }
You can’t perform that action at this time.
0 commit comments