Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const getPatternGetter = (patternChar) => {
};

export const renderDateParts = (text, regExpInfo) => {
const result = regExpInfo.regexp.exec(text);
const result = regExpInfo.regexp.exec(text) ?? [];

let start = 0;
let end = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import eventsEngine from '@js/common/core/events/core/events_engine';
import { addNamespace, isCommandKeyPressed, normalizeKeyName } from '@js/common/core/events/utils/index';
import defaultDateNames from '@js/common/core/localization/default_date_names';
import { getFormat } from '@js/common/core/localization/ldml/date.format';
import { getRegExpInfo } from '@js/common/core/localization/ldml/date.parser';
import numberLocalization from '@js/common/core/localization/number';
Expand Down Expand Up @@ -132,8 +131,7 @@ class DateBoxMask extends DateBoxBase {

_toggleAmPm(): void {
const currentValue = this._getActivePartProp('text');
// @ts-expect-error ts-error
const indexOfCurrentValue = defaultDateNames.getPeriodNames().indexOf(currentValue);
const indexOfCurrentValue = dateLocalization.getPeriodNames().indexOf(currentValue);
const newValue = indexOfCurrentValue ^ 1;
this._setActivePartValue(newValue);
}
Expand Down Expand Up @@ -478,7 +476,7 @@ class DateBoxMask extends DateBoxBase {
}
// @ts-expect-error ts-error
let index = fitIntoRange(this._activePartIndex + step, 0, this._dateParts.length - 1);
if (this._dateParts[index].isStub) {
if (this._dateParts[index]?.isStub) {
const isBoundaryIndex = index === 0 && step < 0 || index === this._dateParts.length - 1 && step > 0;
if (!isBoundaryIndex) {
this._selectNextPart(step >= 0 ? step + 1 : step - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import pointerMock from '../../helpers/pointerMock.js';
import 'ui/date_box';
import keyboardMock from '../../helpers/keyboardMock.js';
import devices from '__internal/core/m_devices';
import localization from 'localization';

const { test, module } = QUnit;

Expand Down Expand Up @@ -1290,6 +1291,32 @@ module('Date AM/PM Handling', setupModule, () => {
assert.strictEqual(this.$input.val(), 'PM');
});
});

test('up/down arrows should continue to switch AM/PM on subsequent presses when locale has localized period names (T1327076)', function(assert) {
const defaultLocale = localization.locale();

try {
localization.locale('es-ES');

const [amName, pmName] = dateLocalization.getPeriodNames();

this.instance.option({
value: new Date('10/10/2012 22:00'),
displayFormat: 'a',
useMaskBehavior: true,
});

assert.strictEqual(this.$input.val(), pmName, 'initial value is localized PM');

this.keyboard.press('up');
assert.strictEqual(this.$input.val(), amName, 'value changed to localized AM after first press');

this.keyboard.press('up');
assert.strictEqual(this.$input.val(), pmName, 'value returned to localized PM after second press');
} finally {
localization.locale(defaultLocale);
}
});
});

module('TimeZone Handling', setupModule, () => {
Expand Down
Loading