11/* eslint-disable class-methods-use-this */
22import eventsEngine from '@js/common/core/events/core/events_engine' ;
33import { addNamespace , isCommandKeyPressed , normalizeKeyName } from '@js/common/core/events/utils/index' ;
4- import defaultDateNames from '@js/common/core/localization/default_date_names' ;
54import { getFormat } from '@js/common/core/localization/ldml/date.format' ;
65import { getRegExpInfo } from '@js/common/core/localization/ldml/date.parser' ;
76import numberLocalization from '@js/common/core/localization/number' ;
@@ -125,7 +124,6 @@ class DateBoxMask extends DateBoxBase {
125124 const delta = currentValue - originalValue ;
126125
127126 this . _loadMaskValue ( this . _initialMaskValue ) ;
128-
129127 this . _changePartValue ( delta + step , true ) ;
130128 }
131129
@@ -142,12 +140,12 @@ class DateBoxMask extends DateBoxBase {
142140
143141 _toggleAmPm ( ) : void {
144142 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 ) ;
143+ const periodNames = dateLocalization . getPeriodNames ( this . _formatPattern ) ;
144+ const indexOfCurrentValue = periodNames . indexOf ( currentValue ) ;
145+
149146 // eslint-disable-next-line no-bitwise
150147 const newValue = indexOfCurrentValue ^ 1 ;
148+
151149 this . _setActivePartValue ( newValue ) ;
152150 }
153151
@@ -543,8 +541,11 @@ class DateBoxMask extends DateBoxBase {
543541 _getActivePartValue ( dateValue ?: Date | null ) : number {
544542 const date = dateValue ?? this . _maskValue as Date ;
545543 const getter = this . _getActivePartProp ( 'getter' ) ;
544+ const isGetterFunction = isFunction ( getter ) ;
545+
546+ const activePartValue = isGetterFunction ? getter ( date ) : date [ getter ] ( ) as number ;
546547
547- return isFunction ( getter ) ? getter ( date ) : date [ getter ] ( ) as number ;
548+ return activePartValue ;
548549 }
549550
550551 _addLeadingZeroes ( value : number ) : string {
@@ -557,6 +558,7 @@ class DateBoxMask extends DateBoxBase {
557558
558559 _setActivePartValue ( value : number | string , dateValue ?: Date ) : void {
559560 let newValue : number | string = + value ;
561+
560562 const newDateValue = dateValue ?? this . _maskValue as Date ;
561563 const setter = this . _getActivePartProp ( 'setter' ) ;
562564 const limits = this . _getActivePartLimits ( ) ;
@@ -569,8 +571,8 @@ class DateBoxMask extends DateBoxBase {
569571 } else {
570572 newDateValue [ setter ] ( newValue ) ;
571573 }
572- this . _renderDisplayText ( this . _getDisplayedText ( newDateValue ) ) ;
573574
575+ this . _renderDisplayText ( this . _getDisplayedText ( newDateValue ) ) ;
574576 this . _renderDateParts ( ) ;
575577 }
576578
0 commit comments