Fix conversion of date to UTC

Method based on one of SO answers: http://stackoverflow.com/questions/948532/how-do-you-convert-a-javascript-date-to-utc
This commit is contained in:
Alexandr Nikitin 2015-03-03 12:26:23 +02:00
parent 9e191bf5c6
commit b0a4d5a84a
2 changed files with 11 additions and 4 deletions

View file

@ -279,10 +279,16 @@
}); });
} }
function dateToUTC(d) { function dateToUTC(d) {
var msDelta = (d.getTimezoneOffset() || 0) * 60000; return new Date(
return new Date(d.getTime() + msDelta); d.getUTCFullYear(),
} d.getUTCMonth(),
d.getUTCDate(),
d.getUTCHours(),
d.getUTCMinutes(),
d.getUTCSeconds(),
d.getUTCMilliseconds());
}
var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds']; var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];
function quacksLikeDate(x) { function quacksLikeDate(x) {

View file

@ -104,6 +104,7 @@ assert.format('%y', '11')
assert.format('%Z', null, 'GMT') assert.format('%Z', null, 'GMT')
assert.format('%z', null, '+0000') assert.format('%z', null, '+0000')
assert.format('%%', '%') // any other char assert.format('%%', '%') // any other char
assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0))
ok('GMT') ok('GMT')