Skip to content

Commit

Permalink
Core - Fix incorrectly date serialization if the year is below '0100'…
Browse files Browse the repository at this point in the history
… (T1025085) (#18980)
  • Loading branch information
dxBeardedBear authored Aug 30, 2021
1 parent f326c07 commit e5f4ad5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions js/core/utils/date_serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ function parseISO8601String(text) {
return;
}

const year = parts[1];
const year = getTimePart(parts[1]);
const month = --parts[3];
const day = parts[5];
let timeZoneHour = 0;
let timeZoneMinute = 0;
const correctYear = (d) => {
year < 100 && d.setFullYear(year);
return d;
};

timeZoneHour = getTimePart(parts[14]);
timeZoneMinute = getTimePart(parts[16]);
Expand All @@ -85,10 +89,10 @@ function parseISO8601String(text) {
const millisecond = parseMilliseconds(parts[11]);

if(parts[12]) {
return new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
return correctYear(new Date(Date.UTC(year, month, day, hour, minute, second, millisecond)));
}

return new Date(year, month, day, hour, minute, second, millisecond);
return correctYear(new Date(year, month, day, hour, minute, second, millisecond));
}

const getIso8601Format = function(text, useUtc) {
Expand Down
8 changes: 8 additions & 0 deletions testing/tests/DevExpress.core/utils.date_parser.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ QUnit.test('date parsing with yyyy-MM-ddThh:mm:ss.SSSSSS', function(assert) {
assert.equal(parsedDate.getTime(), value.getTime());
});

QUnit.test('date parsing if the year is below \'0100\' (T1025085)', function(assert) {
const stringValue = '0021-01-20T01:00:00';

const parsedDate = dateSerialization.dateParser(stringValue);

assert.equal(parsedDate.getFullYear(), 21);
});

QUnit.module('ISO8601 Time Only Formats', {
beforeEach: function() {
this.defaultForceIsoDateParsing = config().forceIsoDateParsing;
Expand Down

0 comments on commit e5f4ad5

Please sign in to comment.