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/artifacts/transpiled-renovation-npm/__internal/ui/date_box/m_date_box.mask.parts.js
  • Loading branch information
nikkithelegendarypokemonster committed Jul 17, 2024
1 parent 4822481 commit d19a3d7
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const PATTERN_GETTERS = {
h: 'getHours',
m: 'getMinutes',
s: 'getSeconds',
S: 'getMilliseconds'
S: 'getMilliseconds',
x: 'getTimezoneOffset',
};
const PATTERN_SETTERS = (0, _extend.extend)({}, (0, _date.getPatternSetters)(), {
a: (date, value) => {
Expand Down Expand Up @@ -76,7 +77,8 @@ const PATTERN_SETTERS = (0, _extend.extend)({}, (0, _date.getPatternSetters)(),
// eslint-disable-next-line radix
const newValue = parseInt(String(currentYear).substr(0, maxLimitLength - valueLength) + value);
date.setFullYear(newValue);
}
},
x: (date) => date,
});
const getPatternGetter = patternChar => {
const unsupportedCharGetter = () => patternChar;
Expand Down Expand Up @@ -165,7 +167,8 @@ const getLimits = (pattern, date, forcedPattern) => {
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
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 d19a3d7

Please sign in to comment.