@@ -278,14 +278,15 @@ class Dayjs {
278
278
const str = formatStr || C . FORMAT_DEFAULT
279
279
const zoneStr = Utils . z ( this )
280
280
const locale = this . $locale ( )
281
+ const { $H, $m, $M } = this
281
282
const {
282
283
weekdays, months, meridiem
283
284
} = locale
284
285
const getShort = ( arr , index , full , length ) => (
285
- ( arr && arr [ index ] ) || full [ index ] . substr ( 0 , length )
286
+ ( arr && ( arr [ index ] || arr ( this , str ) ) ) || full [ index ] . substr ( 0 , length )
286
287
)
287
288
const get$H = num => (
288
- Utils . s ( this . $H % 12 || 12 , num , '0' )
289
+ Utils . s ( $H % 12 || 12 , num , '0' )
289
290
)
290
291
291
292
const meridiemFunc = meridiem || ( ( hour , minute , isLowercase ) => {
@@ -295,32 +296,32 @@ class Dayjs {
295
296
296
297
const matches = {
297
298
YY : String ( this . $y ) . slice ( - 2 ) ,
298
- YYYY : String ( this . $y ) ,
299
- M : String ( this . $M + 1 ) ,
300
- MM : Utils . s ( this . $M + 1 , 2 , '0' ) ,
301
- MMM : getShort ( locale . monthsShort , this . $M , months , 3 ) ,
302
- MMMM : months [ this . $M ] ,
303
- D : String ( this . $D ) ,
299
+ YYYY : this . $y ,
300
+ M : $M + 1 ,
301
+ MM : Utils . s ( $M + 1 , 2 , '0' ) ,
302
+ MMM : getShort ( locale . monthsShort , $M , months , 3 ) ,
303
+ MMMM : months [ $M ] || months ( this , str ) ,
304
+ D : this . $D ,
304
305
DD : Utils . s ( this . $D , 2 , '0' ) ,
305
- d : String ( this . $W ) ,
306
+ d : this . $W ,
306
307
dd : getShort ( locale . weekdaysMin , this . $W , weekdays , 2 ) ,
307
308
ddd : getShort ( locale . weekdaysShort , this . $W , weekdays , 3 ) ,
308
309
dddd : weekdays [ this . $W ] ,
309
- H : String ( this . $H ) ,
310
- HH : Utils . s ( this . $H , 2 , '0' ) ,
310
+ H : $H ,
311
+ HH : Utils . s ( $H , 2 , '0' ) ,
311
312
h : get$H ( 1 ) ,
312
313
hh : get$H ( 2 ) ,
313
- a : meridiemFunc ( this . $H , this . $m , true ) ,
314
- A : meridiemFunc ( this . $H , this . $m , false ) ,
315
- m : String ( this . $m ) ,
316
- mm : Utils . s ( this . $m , 2 , '0' ) ,
317
- s : String ( this . $s ) ,
314
+ a : meridiemFunc ( $H , $m , true ) ,
315
+ A : meridiemFunc ( $H , $m , false ) ,
316
+ m : $m ,
317
+ mm : Utils . s ( $m , 2 , '0' ) ,
318
+ s : this . $s ,
318
319
ss : Utils . s ( this . $s , 2 , '0' ) ,
319
320
SSS : Utils . s ( this . $ms , 3 , '0' ) ,
320
321
Z : zoneStr // 'ZZ' logic below
321
322
}
322
323
323
- return str . replace ( C . REGEX_FORMAT , ( match , $1 ) => $1 || matches [ match ] || zoneStr . replace ( ':' , '' ) ) // 'ZZ'
324
+ return String ( str . replace ( C . REGEX_FORMAT , ( match , $1 ) => $1 || matches [ match ] || zoneStr . replace ( ':' , '' ) ) ) // 'ZZ'
324
325
}
325
326
326
327
utcOffset ( ) {
0 commit comments