Skip to content

Commit 8fcc551

Browse files
author
marker dao ®
committed
DateBox: Use localized day period names (T1327076)
1 parent 0e679a0 commit 8fcc551

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 3 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
}

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

Lines changed: 26 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,31 @@ 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+
});
1307+
1308+
assert.strictEqual(this.$input.val(), pmName, 'initial value is localized PM');
1309+
1310+
this.keyboard.press('up');
1311+
assert.strictEqual(this.$input.val(), amName, 'value changed to localized AM after first press');
1312+
1313+
this.keyboard.press('up');
1314+
assert.strictEqual(this.$input.val(), pmName, 'value returned to localized PM after second press');
1315+
} finally {
1316+
localization.locale(defaultLocale);
1317+
}
1318+
});
12931319
});
12941320

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

0 commit comments

Comments
 (0)