Skip to content

Commit

Permalink
DateBox: update regex pattern add 'x' (T1241387) (#27794)
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]>
  • Loading branch information
nikkithelegendarypokemonster and ksercs authored Jul 17, 2024
1 parent e8680c7 commit 9c595d7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
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) {
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 9c595d7

Please sign in to comment.