Skip to content

Commit 65ceb37

Browse files
marker-daomarker dao ®
andauthored
DateBox: Use localized day period names (T1327076) (#33367)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent 0e679a0 commit 65ceb37

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.parts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const getPatternGetter = (patternChar) => {
8989
};
9090

9191
export const renderDateParts = (text, regExpInfo) => {
92-
const result = regExpInfo.regexp.exec(text);
92+
const result = regExpInfo.regexp.exec(text) ?? [];
9393

9494
let start = 0;
9595
let end = 0;

packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import eventsEngine from '@js/common/core/events/core/events_engine';
22
import { addNamespace, isCommandKeyPressed, normalizeKeyName } from '@js/common/core/events/utils/index';
3-
import defaultDateNames from '@js/common/core/localization/default_date_names';
43
import { getFormat } from '@js/common/core/localization/ldml/date.format';
54
import { getRegExpInfo } from '@js/common/core/localization/ldml/date.parser';
65
import numberLocalization from '@js/common/core/localization/number';
@@ -132,8 +131,7 @@ class DateBoxMask extends DateBoxBase {
132131

133132
_toggleAmPm(): void {
134133
const currentValue = this._getActivePartProp('text');
135-
// @ts-expect-error ts-error
136-
const indexOfCurrentValue = defaultDateNames.getPeriodNames().indexOf(currentValue);
134+
const indexOfCurrentValue = dateLocalization.getPeriodNames().indexOf(currentValue);
137135
const newValue = indexOfCurrentValue ^ 1;
138136
this._setActivePartValue(newValue);
139137
}
@@ -478,7 +476,7 @@ class DateBoxMask extends DateBoxBase {
478476
}
479477
// @ts-expect-error ts-error
480478
let index = fitIntoRange(this._activePartIndex + step, 0, this._dateParts.length - 1);
481-
if (this._dateParts[index].isStub) {
479+
if (this._dateParts[index]?.isStub) {
482480
const isBoundaryIndex = index === 0 && step < 0 || index === this._dateParts.length - 1 && step > 0;
483481
if (!isBoundaryIndex) {
484482
this._selectNextPart(step >= 0 ? step + 1 : step - 1);

packages/devextreme/testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import pointerMock from '../../helpers/pointerMock.js';
77
import 'ui/date_box';
88
import keyboardMock from '../../helpers/keyboardMock.js';
99
import devices from '__internal/core/m_devices';
10+
import localization from 'localization';
1011

1112
const { test, module } = QUnit;
1213

@@ -1290,6 +1291,32 @@ module('Date AM/PM Handling', setupModule, () => {
12901291
assert.strictEqual(this.$input.val(), 'PM');
12911292
});
12921293
});
1294+
1295+
test('up/down arrows should continue to switch AM/PM on subsequent presses when locale has localized period names (T1327076)', function(assert) {
1296+
const defaultLocale = localization.locale();
1297+
1298+
try {
1299+
localization.locale('es-ES');
1300+
1301+
const [amName, pmName] = dateLocalization.getPeriodNames();
1302+
1303+
this.instance.option({
1304+
value: new Date('10/10/2012 22:00'),
1305+
displayFormat: 'a',
1306+
useMaskBehavior: true,
1307+
});
1308+
1309+
assert.strictEqual(this.$input.val(), pmName, 'initial value is localized PM');
1310+
1311+
this.keyboard.press('up');
1312+
assert.strictEqual(this.$input.val(), amName, 'value changed to localized AM after first press');
1313+
1314+
this.keyboard.press('up');
1315+
assert.strictEqual(this.$input.val(), pmName, 'value returned to localized PM after second press');
1316+
} finally {
1317+
localization.locale(defaultLocale);
1318+
}
1319+
});
12931320
});
12941321

12951322
module('TimeZone Handling', setupModule, () => {

0 commit comments

Comments
 (0)