Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateBox: update regex pattern add 'x' (T1241387) #27770

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 @@ -32,6 +32,7 @@ const PATTERN_GETTERS = {
m: 'getMinutes',
s: 'getSeconds',
S: 'getMilliseconds',
x: 'getTimezoneOffset',
};

const PATTERN_SETTERS = extend({}, getPatternSetters(), {
Expand Down Expand Up @@ -79,6 +80,7 @@ const PATTERN_SETTERS = extend({}, getPatternSetters(), {

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

const getPatternGetter = (patternChar) => {
Expand Down Expand Up @@ -134,6 +136,7 @@ const getLimits = (pattern, date, forcedPattern) => {
s: { min: 0, max: 59 },
S: { min: 0, max: 999 },
a: { min: 0, max: 1 },
x: { min: 0, max: 0 }, // NOTE: Timezone part is read only.
};
// @ts-expect-error
return limits[forcedPattern || pattern] || limits.getAmPm;
Expand Down
3 changes: 3 additions & 0 deletions packages/devextreme/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
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,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) {
nikkithelegendarypokemonster marked this conversation as resolved.
Show resolved Hide resolved
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');
nikkithelegendarypokemonster marked this conversation as resolved.
Show resolved Hide resolved
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
Loading