Fix XSD parsing of non-Zulu times

This commit is contained in:
Andreas Hocevar
2016-07-26 16:32:46 +02:00
parent cd8fafbead
commit e2d96082f9
2 changed files with 19 additions and 3 deletions

View File

@@ -55,10 +55,10 @@ ol.format.XSD.readDateTime = function(node) {
var second = parseInt(m[6], 10); var second = parseInt(m[6], 10);
var dateTime = Date.UTC(year, month, day, hour, minute, second) / 1000; var dateTime = Date.UTC(year, month, day, hour, minute, second) / 1000;
if (m[7] != 'Z') { if (m[7] != 'Z') {
var sign = m[8] == '-' ? -1 : 1; var sign = m[8] == '-' ? 1 : -1;
dateTime += sign * 60 * parseInt(m[9], 10); dateTime += sign * 60 * 60 * parseInt(m[9], 10);
if (m[10] !== undefined) { if (m[10] !== undefined) {
dateTime += sign * 60 * 60 * parseInt(m[10], 10); dateTime += sign * 60 * parseInt(m[10], 10);
} }
} }
return dateTime; return dateTime;

View File

@@ -0,0 +1,16 @@
goog.provide('ol.test.XSD');
describe('ol.format.XSD', function() {
describe('readDateTime', function() {
it('can handle non-Zulu time zones', function() {
var node = document.createElement('time');
node.textContent = '2016-07-12T15:00:00+03:00';
expect(new Date(ol.format.XSD.readDateTime(node) * 1000).toISOString()).to.eql('2016-07-12T12:00:00.000Z');
});
});
});
goog.require('ol.format.XSD');