1- /* eslint-disable class-methods-use-this */
21import eventsEngine from '@js/common/core/events/core/events_engine' ;
32import { addNamespace , isCommandKeyPressed , normalizeKeyName } from '@js/common/core/events/utils/index' ;
4- import defaultDateNames from '@js/common/core/localization/default_date_names' ;
53import { getFormat } from '@js/common/core/localization/ldml/date.format' ;
64import { getRegExpInfo } from '@js/common/core/localization/ldml/date.parser' ;
75import numberLocalization from '@js/common/core/localization/number' ;
@@ -125,7 +123,6 @@ class DateBoxMask extends DateBoxBase {
125123 const delta = currentValue - originalValue ;
126124
127125 this . _loadMaskValue ( this . _initialMaskValue ) ;
128-
129126 this . _changePartValue ( delta + step , true ) ;
130127 }
131128
@@ -142,12 +139,12 @@ class DateBoxMask extends DateBoxBase {
142139
143140 _toggleAmPm ( ) : void {
144141 const currentValue = this . _getActivePartProp ( 'text' ) ;
145- const indexOfCurrentValue = defaultDateNames
146- // @ts -expect-error getPeriodNames type should be fixed
147- . getPeriodNames ( this . _formatPattern )
148- . indexOf ( currentValue ) ;
142+ const periodNames = dateLocalization . getPeriodNames ( this . _formatPattern ) ;
143+ const indexOfCurrentValue = periodNames . indexOf ( currentValue ) ;
144+
149145 // eslint-disable-next-line no-bitwise
150146 const newValue = indexOfCurrentValue ^ 1 ;
147+
151148 this . _setActivePartValue ( newValue ) ;
152149 }
153150
@@ -505,7 +502,7 @@ class DateBoxMask extends DateBoxBase {
505502
506503 const activePartIndex = this . _activePartIndex ?? 0 ;
507504 let index = fitIntoRange ( activePartIndex + step , 0 , this . _dateParts . length - 1 ) ;
508- if ( this . _dateParts [ index ] . isStub ) {
505+ if ( this . _dateParts [ index ] ? .isStub ) {
509506 const isBoundaryIndex = ( index === 0 && step < 0 )
510507 || ( index === this . _dateParts . length - 1 && step > 0 ) ;
511508 if ( ! isBoundaryIndex ) {
@@ -543,8 +540,11 @@ class DateBoxMask extends DateBoxBase {
543540 _getActivePartValue ( dateValue ?: Date | null ) : number {
544541 const date = dateValue ?? this . _maskValue as Date ;
545542 const getter = this . _getActivePartProp ( 'getter' ) ;
543+ const isGetterFunction = isFunction ( getter ) ;
544+
545+ const activePartValue = isGetterFunction ? getter ( date ) : date [ getter ] ( ) as number ;
546546
547- return isFunction ( getter ) ? getter ( date ) : date [ getter ] ( ) as number ;
547+ return activePartValue ;
548548 }
549549
550550 _addLeadingZeroes ( value : number ) : string {
@@ -557,6 +557,7 @@ class DateBoxMask extends DateBoxBase {
557557
558558 _setActivePartValue ( value : number | string , dateValue ?: Date ) : void {
559559 let newValue : number | string = + value ;
560+
560561 const newDateValue = dateValue ?? this . _maskValue as Date ;
561562 const setter = this . _getActivePartProp ( 'setter' ) ;
562563 const limits = this . _getActivePartLimits ( ) ;
@@ -569,8 +570,8 @@ class DateBoxMask extends DateBoxBase {
569570 } else {
570571 newDateValue [ setter ] ( newValue ) ;
571572 }
572- this . _renderDisplayText ( this . _getDisplayedText ( newDateValue ) ) ;
573573
574+ this . _renderDisplayText ( this . _getDisplayedText ( newDateValue ) ) ;
574575 this . _renderDateParts ( ) ;
575576 }
576577
0 commit comments