Skip to content

Commit

Permalink
Fix for IE11 and IE20
Browse files Browse the repository at this point in the history
  • Loading branch information
Xotic750 committed Dec 10, 2015
1 parent 67d99f1 commit b4560ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
11 changes: 4 additions & 7 deletions es5-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,10 @@ defineProperties($Object, {
// ====
//

var hasNegativeMonthYearBug = new Date(-3509827334573292).getUTCMonth() === 12;
var hasToDateStringFormatBug = new Date(1449662400000).toDateString() !== 'Wed Dec 09 2015';
var hasToUTCStringFormatBug = new Date(1449662400000).toUTCString() !== 'Wed, 09 Dec 2015 12:00:00 GMT';
var negativeTestDate = new Date(-3509827329600292);
var hasNegativeMonthYearBug = negativeTestDate.getUTCMonth() === 12;
var hasToDateStringFormatBug = negativeTestDate.toDateString() !== 'Thu Jan 01 -109252';
var hasToUTCStringFormatBug = negativeTestDate.toUTCString() !== 'Thu, 01 Jan -109252 11:59:59 GMT';
var hasToStringFormatBug = !(/^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(new Date(1449662400000).toString());
var originalGetFullYear;
var originalGetMonth;
Expand Down Expand Up @@ -1102,10 +1103,6 @@ defineProperties(Date.prototype, {
}
}, hasNegativeMonthYearBug);

if (hasNegativeMonthYearBug || hasToUTCStringFormatBug) {
delete Date.prototype.toUTCString;
}

defineProperties(Date.prototype, {
toUTCString: function toUTCString() {
if (!this || !(this instanceof Date)) {
Expand Down
47 changes: 25 additions & 22 deletions tests/spec/s-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ describe('Date', function () {
var ifSupportsDescriptorsIt = supportsDescriptors ? it : xit;
var has = Object.prototype.hasOwnProperty;

var negativeDate;
beforeEach(function () {
negativeDate = new Date(-3509827329600292);
});

describe('.now()', function () {
it('should be the current time', function () {
var before = (new Date()).getTime();
Expand Down Expand Up @@ -211,27 +216,27 @@ describe('Date', function () {
describe('#getUTCDate()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getUTCDate()).toBe(1);
expect(negativeDate.getUTCDate()).toBe(1);
});
});

describe('#getUTCDay()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getUTCDay()).toBe(4);
expect(negativeDate.getUTCDay()).toBe(4);
});
});

describe('#getUTCFullYear()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getUTCFullYear()).toBe(-109252);
expect(negativeDate.getUTCFullYear()).toBe(-109252);
});
});

describe('#getUTCMonth()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getUTCMonth()).toBe(0);
expect(negativeDate.getUTCMonth()).toBe(0);
});

it('should return correct values', function () {
Expand All @@ -242,82 +247,80 @@ describe('Date', function () {

describe('#getUTCHours()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getUTCHours()).toBe(10);
expect(negativeDate.getUTCHours()).toBe(11);
});
});

describe('#getUTCMinutes()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getUTCMinutes()).toBe(37);
expect(negativeDate.getUTCMinutes()).toBe(59);
});
});

describe('#getUTCSeconds()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getUTCSeconds()).toBe(6);
expect(negativeDate.getUTCSeconds()).toBe(59);
});
});

describe('#getUTCMilliseconds()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getUTCMilliseconds()).toBe(708);
expect(negativeDate.getUTCMilliseconds()).toBe(708);
});
});

describe('#getDate()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getDate()).toBe(1);
expect(negativeDate.getDate()).toBe(1);
});
});

describe('#getDay()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getDay()).toBe(4);
expect(negativeDate.getDay()).toBe(4);
});
});

describe('#getFullYear()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getFullYear()).toBe(-109252);
expect(negativeDate.getFullYear()).toBe(-109252);
});
});

describe('#getMonth()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getMonth()).toBe(0);
expect(negativeDate.getMonth()).toBe(0);
});
});

describe('#getHours()', function () {
it('should return the right value for negative dates', function () {
var date = new Date(-3509827334573292);
expect(date.getHours() + Math.floor(date.getTimezoneOffset() / 60)).toBe(10);
expect(negativeDate.getHours() + Math.floor(negativeDate.getTimezoneOffset() / 60)).toBe(11);
});
});

describe('#getMinutes()', function () {
it('should return the right value for negative dates', function () {
var date = new Date(-3509827334573292);
var off = date.getTimezoneOffset();
var off = negativeDate.getTimezoneOffset();
var offHours = Math.floor(off / 60);
var offMins = off - offHours * 60;
expect(date.getMinutes() + offMins).toBe(37);
expect(negativeDate.getMinutes() + offMins).toBe(59);
});
});

describe('#getSeconds()', function () {
it('should return the right value for negative dates', function () {
expect(new Date(-3509827334573292).getSeconds()).toBe(6);
expect(negativeDate.getSeconds()).toBe(59);
});
});

describe('#getMilliseconds()', function () {
it('should return the right value for negative dates', function () {
// Opera 10.6/11.61/Opera 12 bug
expect(new Date(-3509827334573292).getMilliseconds()).toBe(708);
expect(negativeDate.getMilliseconds()).toBe(708);
});
});

Expand All @@ -331,20 +334,20 @@ describe('Date', function () {

it('should return correct dates', function () {
expect(new Date(-1).toISOString()).toBe('1969-12-31T23:59:59.999Z');// Safari 5.1.5 "1969-12-31T23:59:59.-01Z"
expect(new Date(-3509827334573292).toISOString()).toBe('-109252-01-01T10:37:06.708Z'); // Opera 11.61/Opera 12 bug with Date#getUTCMonth
expect(negativeDate.toISOString()).toBe('-109252-01-01T11:59:59.708Z'); // Opera 11.61/Opera 12 bug with Date#getUTCMonth
});

});

describe('#toUTCString()', function () {
it('should return correct dates', function () {
expect(new Date(-3509827334573292).toUTCString()).toBe('Thu, 01 Jan -109252 10:37:06 GMT');
expect(negativeDate.toUTCString()).toBe('Thu, 01 Jan -109252 11:59:59 GMT');
});
});

describe('#toDateString()', function () {
it('should return correct dates', function () {
expect(new Date(-3509827334573292).toDateString()).toBe('Thu Jan 01 -109252');
expect(negativeDate.toDateString()).toBe('Thu Jan 01 -109252');
});
});

Expand Down

0 comments on commit b4560ee

Please sign in to comment.