Skip to content

Commit

Permalink
DateBox: update regex pattern add 'x' (T1241387) (DevExpress#27770)
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kuznetsov <[email protected]>
Co-authored-by: Anton Kuznetsov <[email protected]>
# Conflicts:
#	packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.parts.ts
  • Loading branch information
nikkithelegendarypokemonster committed Jul 17, 2024
1 parent 361a70a commit 9771d78
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
3 changes: 3 additions & 0 deletions js/localization/ldml/date.parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const PATTERN_REGEXPS = {
},
w: function(count) {
return count === 2 ? '[1-5][0-9]|0?[0-9]' : '0??[0-9]|[1-5][0-9]';
},
x: function(count) {
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';
}
};

Expand Down
9 changes: 6 additions & 3 deletions js/ui/date_box/ui.date_box.mask.parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const PATTERN_GETTERS = {
h: 'getHours',
m: 'getMinutes',
s: 'getSeconds',
S: 'getMilliseconds'
S: 'getMilliseconds',
x: 'getTimezoneOffset',
};

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

date.setFullYear(newValue);
}
},
x: (date) => date,
});

const getPatternGetter = (patternChar) => {
Expand Down Expand Up @@ -126,7 +128,8 @@ const getLimits = (pattern, date, forcedPattern) => {
m: { min: 0, max: 59 },
s: { min: 0, max: 59 },
S: { min: 0, max: 999 },
a: { min: 0, max: 1 }
a: { min: 0, max: 1 },
x: { min: 0, max: 0 }, // NOTE: Timezone part is read only.
};

return limits[forcedPattern || pattern] || limits['getAmPm'];
Expand Down
34 changes: 34 additions & 0 deletions testing/tests/DevExpress.ui.widgets.editors/datebox.mask.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,40 @@ module('Date AM/PM Handling', setupModule, () => {
});
});

module('TimeZone Handling', setupModule, () => {
test('should support \'x\' in date pattern and not generate errors (T1241387)', function(assert) {
try {
this.instance.option({
displayFormat: 'yyyy-MM-dd\'T\'HH:mm:ssxxx',
useMaskBehavior: true,
type: 'date',
});
assert.ok(true, 'no error shown');
} catch(e) {
assert.ok(false, 'error exists');
}
});

test('should not show error when changing timezone on runtime via up/down buttons (T1241387)', function(assert) {
try {
this.instance.option({
displayFormat: 'yyyy-MM-dd\'T\'HH:mm:ssxxx',
useMaskBehavior: true,
type: 'date',
});
const oldValue = this.$input.val();
this.keyboard.caret({ start: 20, end: 24 });
this.$input.focus().trigger('dxclick');
this.keyboard.press('up');

assert.ok(true, 'no error shown');
assert.strictEqual(this.$input.val(), oldValue, 'value has not been modified');
} catch(e) {
assert.ok(false, 'error exists');
}
});
});

module('Empty dateBox', {
beforeEach: function() {
setupModule.beforeEach.call(this);
Expand Down

0 comments on commit 9771d78

Please sign in to comment.