From e2d96082f91a7f36eb6c50c63f8602da3ae2d1ff Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Tue, 26 Jul 2016 16:32:46 +0200 Subject: [PATCH] Fix XSD parsing of non-Zulu times --- src/ol/format/xsdformat.js | 6 +++--- test/spec/ol/format/xsdformat.test.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/spec/ol/format/xsdformat.test.js diff --git a/src/ol/format/xsdformat.js b/src/ol/format/xsdformat.js index d5de2663ce..b132a233a5 100644 --- a/src/ol/format/xsdformat.js +++ b/src/ol/format/xsdformat.js @@ -55,10 +55,10 @@ ol.format.XSD.readDateTime = function(node) { var second = parseInt(m[6], 10); var dateTime = Date.UTC(year, month, day, hour, minute, second) / 1000; if (m[7] != 'Z') { - var sign = m[8] == '-' ? -1 : 1; - dateTime += sign * 60 * parseInt(m[9], 10); + var sign = m[8] == '-' ? 1 : -1; + dateTime += sign * 60 * 60 * parseInt(m[9], 10); if (m[10] !== undefined) { - dateTime += sign * 60 * 60 * parseInt(m[10], 10); + dateTime += sign * 60 * parseInt(m[10], 10); } } return dateTime; diff --git a/test/spec/ol/format/xsdformat.test.js b/test/spec/ol/format/xsdformat.test.js new file mode 100644 index 0000000000..492b03c941 --- /dev/null +++ b/test/spec/ol/format/xsdformat.test.js @@ -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');