From d90b7b6714f3bb195950108005a8ff8cfc0d667f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 24 Feb 2016 01:45:38 -0800 Subject: [PATCH] [Fix] `new Date(new Date())` should work in IE 8. Fixes #389. --- es5-shim.js | 2 +- tests/spec/s-date.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/es5-shim.js b/es5-shim.js index f8d8878c..d9d87d65 100644 --- a/es5-shim.js +++ b/es5-shim.js @@ -1418,7 +1418,7 @@ if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) { length >= 4 ? new NativeDate(Y, M, D, h) : length >= 3 ? new NativeDate(Y, M, D) : length >= 2 ? new NativeDate(Y, M) : - length >= 1 ? new NativeDate(Y) : + length >= 1 ? new NativeDate(Y instanceof NativeDate ? +Y : Y) : new NativeDate(); } else { date = NativeDate.apply(this, arguments); diff --git a/tests/spec/s-date.js b/tests/spec/s-date.js index e46a1946..1684926a 100644 --- a/tests/spec/s-date.js +++ b/tests/spec/s-date.js @@ -167,6 +167,15 @@ describe('Date', function () { var expectedVeryBrokenTS = veryBrokenTS + (largeDate.getTimezoneOffset() * 60e3); expect(veryBrokenDate.getTime()).toBe(expectedVeryBrokenTS); // NaN in Safari 8/9 }); + + it('works with a Date object', function () { + var date = new Date(1456297712984); + var copiedDate = new Date(date); + expect(date).not.toBe(copiedDate); + expect(copiedDate.getTime()).toBe(date.getTime()); + expect(+copiedDate).toBe(+date); + expect(String(copiedDate)).toBe(String(date)); + }); }); describe('.parse()', function () {