mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
Merge pull request #48 from alexandrnikitin/Issue47_UtcConversionDoesntWorkCorrectly
(Fixes #47) Fix conversion of date to UTC
This commit is contained in:
commit
9146f45142
2 changed files with 19 additions and 4 deletions
22
strftime.js
22
strftime.js
|
|
@ -279,10 +279,24 @@
|
|||
});
|
||||
}
|
||||
|
||||
function dateToUTC(d) {
|
||||
var msDelta = (d.getTimezoneOffset() || 0) * 60000;
|
||||
return new Date(d.getTime() + msDelta);
|
||||
}
|
||||
function dateToUTC(d) {
|
||||
var year = d.getUTCFullYear();
|
||||
var date = new Date(
|
||||
year,
|
||||
d.getUTCMonth(),
|
||||
d.getUTCDate(),
|
||||
d.getUTCHours(),
|
||||
d.getUTCMinutes(),
|
||||
d.getUTCSeconds(),
|
||||
d.getUTCMilliseconds()
|
||||
);
|
||||
// In old dates, years is incorrectly interpreted as a 2-digit year with base 1900.
|
||||
// Correct this by setting the year explicitly after the fuzzy creation process.
|
||||
if (date.getFullYear() != year) {
|
||||
date.setFullYear(year);
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];
|
||||
function quacksLikeDate(x) {
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ assert.format('%y', '11')
|
|||
assert.format('%Z', null, 'GMT')
|
||||
assert.format('%z', null, '+0000')
|
||||
assert.format('%%', '%') // any other char
|
||||
assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0))
|
||||
ok('GMT')
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue