Skip to content

Commit cba32f7

Browse files
authored
Merge pull request #45 from nightskylark/T612757
Fix date parsing by a custom parsers
2 parents 9d328a1 + 1331a87 commit cba32f7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/date.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ dateLocalization.inject({
195195

196196
var formatter;
197197

198-
if(dxVersion >= '17.2.4' && format && typeof dateString === 'string') {
198+
if(dxVersion >= '17.2.4' && format && !format.parser && typeof dateString === 'string') {
199199
dateString = normalizeMonth(dateString);
200200
formatter = function(date) {
201201
return normalizeMonth(dateLocalization.format(date, format));

tests/date-tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ locales.forEach(function(localeId) {
328328
assert.equal(dateLocalization.parse('', 'shortDate'), undefined);
329329
});
330330

331+
QUnit.test('parse by a function', function(assert) {
332+
var expectedDate = new Date(2018, 1, 1);
333+
var customDateString = 'Custom date string';
334+
var customParser = function(text) {
335+
if(text === customDateString) {
336+
return expectedDate;
337+
}
338+
};
339+
assert.equal(dateLocalization.parse(customDateString, { parser: customParser }).toString(), expectedDate.toString());
340+
});
341+
331342
QUnit.test('DevExtreme format uses default locale options', function(assert) {
332343
var date = new Date();
333344

0 commit comments

Comments
 (0)