Skip to content

Commit abd0d84

Browse files
DateBox: update regex pattern add 'x' (T1241387) (#27797)
1 parent 361a70a commit abd0d84

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

js/localization/ldml/date.parser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const PATTERN_REGEXPS = {
6262
},
6363
w: function(count) {
6464
return count === 2 ? '[1-5][0-9]|0?[0-9]' : '0??[0-9]|[1-5][0-9]';
65+
},
66+
x: function(count) {
67+
return count === 3 ? '[+-](?:2[0-3]|[01][0-9]):(?:[0-5][0-9])|Z' : '[+-](?:2[0-3]|[01][0-9])(?:[0-5][0-9])|Z';
6568
}
6669
};
6770

js/ui/date_box/ui.date_box.mask.parts.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const PATTERN_GETTERS = {
3131
h: 'getHours',
3232
m: 'getMinutes',
3333
s: 'getSeconds',
34-
S: 'getMilliseconds'
34+
S: 'getMilliseconds',
35+
x: 'getTimezoneOffset',
3536
};
3637

3738
const PATTERN_SETTERS = extend({}, getPatternSetters(), {
@@ -73,7 +74,8 @@ const PATTERN_SETTERS = extend({}, getPatternSetters(), {
7374
const newValue = parseInt(String(currentYear).substr(0, maxLimitLength - valueLength) + value);
7475

7576
date.setFullYear(newValue);
76-
}
77+
},
78+
x: (date) => date,
7779
});
7880

7981
const getPatternGetter = (patternChar) => {
@@ -126,7 +128,8 @@ const getLimits = (pattern, date, forcedPattern) => {
126128
m: { min: 0, max: 59 },
127129
s: { min: 0, max: 59 },
128130
S: { min: 0, max: 999 },
129-
a: { min: 0, max: 1 }
131+
a: { min: 0, max: 1 },
132+
x: { min: 0, max: 0 }, // NOTE: Timezone part is read only.
130133
};
131134

132135
return limits[forcedPattern || pattern] || limits['getAmPm'];

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,40 @@ module('Date AM/PM Handling', setupModule, () => {
12671267
});
12681268
});
12691269

1270+
module('TimeZone Handling', setupModule, () => {
1271+
test('should support \'x\' in date pattern and not generate errors (T1241387)', function(assert) {
1272+
try {
1273+
this.instance.option({
1274+
displayFormat: 'yyyy-MM-dd\'T\'HH:mm:ssxxx',
1275+
useMaskBehavior: true,
1276+
type: 'date',
1277+
});
1278+
assert.ok(true, 'no error shown');
1279+
} catch(e) {
1280+
assert.ok(false, 'error exists');
1281+
}
1282+
});
1283+
1284+
test('should not show error when changing timezone on runtime via up/down buttons (T1241387)', function(assert) {
1285+
try {
1286+
this.instance.option({
1287+
displayFormat: 'yyyy-MM-dd\'T\'HH:mm:ssxxx',
1288+
useMaskBehavior: true,
1289+
type: 'date',
1290+
});
1291+
const oldValue = this.$input.val();
1292+
this.keyboard.caret({ start: 20, end: 24 });
1293+
this.$input.focus().trigger('dxclick');
1294+
this.keyboard.press('up');
1295+
1296+
assert.ok(true, 'no error shown');
1297+
assert.strictEqual(this.$input.val(), oldValue, 'value has not been modified');
1298+
} catch(e) {
1299+
assert.ok(false, 'error exists');
1300+
}
1301+
});
1302+
});
1303+
12701304
module('Empty dateBox', {
12711305
beforeEach: function() {
12721306
setupModule.beforeEach.call(this);

0 commit comments

Comments
 (0)