+var hasNegativeMonthYearBug = new Date(-3509827329600292).getUTCMonth() !== 0;
+var aNegativeTestDate = new Date(-1509842289600292);
+var aPositiveTestDate = new Date(1449662400000);
+var hasToUTCStringFormatBug = aNegativeTestDate.toUTCString() !== 'Mon, 01 Jan -45875 11:59:59 GMT';
+var hasToDateStringFormatBug;
+var hasToStringFormatBug;
+var timeZoneOffset = aNegativeTestDate.getTimezoneOffset();
+if (timeZoneOffset < -720) {
+ hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Tue Jan 02 -45875';
+ hasToStringFormatBug = !(/^Thu Dec 10 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(aPositiveTestDate.toString());
+} else {
+ hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Mon Jan 01 -45875';
+ hasToStringFormatBug = !(/^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(aPositiveTestDate.toString());
+}
+
+var originalGetFullYear = call.bind(Date.prototype.getFullYear);
+var originalGetMonth = call.bind(Date.prototype.getMonth);
+var originalGetDate = call.bind(Date.prototype.getDate);
+var originalGetUTCFullYear = call.bind(Date.prototype.getUTCFullYear);
+var originalGetUTCMonth = call.bind(Date.prototype.getUTCMonth);
+var originalGetUTCDate = call.bind(Date.prototype.getUTCDate);
+var originalGetUTCDay = call.bind(Date.prototype.getUTCDay);
+var originalGetUTCHours = call.bind(Date.prototype.getUTCHours);
+var originalGetUTCMinutes = call.bind(Date.prototype.getUTCMinutes);
+var originalGetUTCSeconds = call.bind(Date.prototype.getUTCSeconds);
+var originalGetUTCMilliseconds = call.bind(Date.prototype.getUTCMilliseconds);
+var dayName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
+var monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+var daysInMonth = function daysInMonth(month, year) {
+ return originalGetDate(new Date(year, month, 0));
+};
+
+defineProperties(Date.prototype, {
+ getFullYear: function getFullYear() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var year = originalGetFullYear(this);
+ if (year < 0 && originalGetMonth(this) > 11) {
+ return year + 1;
+ }
+ return year;
+ },
+ getMonth: function getMonth() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var year = originalGetFullYear(this);
+ var month = originalGetMonth(this);
+ if (year < 0 && month > 11) {
+ return 0;
+ }
+ return month;
+ },
+ getDate: function getDate() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var year = originalGetFullYear(this);
+ var month = originalGetMonth(this);
+ var date = originalGetDate(this);
+ if (year < 0 && month > 11) {
+ if (month === 12) {
+ return date;
+ }
+ var days = daysInMonth(0, year + 1);
+ return (days - date) + 1;
+ }
+ return date;
+ },
+ getUTCFullYear: function getUTCFullYear() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var year = originalGetUTCFullYear(this);
+ if (year < 0 && originalGetUTCMonth(this) > 11) {
+ return year + 1;
+ }
+ return year;
+ },
+ getUTCMonth: function getUTCMonth() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var year = originalGetUTCFullYear(this);
+ var month = originalGetUTCMonth(this);
+ if (year < 0 && month > 11) {
+ return 0;
+ }
+ return month;
+ },
+ getUTCDate: function getUTCDate() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var year = originalGetUTCFullYear(this);
+ var month = originalGetUTCMonth(this);
+ var date = originalGetUTCDate(this);
+ if (year < 0 && month > 11) {
+ if (month === 12) {
+ return date;
+ }
+ var days = daysInMonth(0, year + 1);
+ return (days - date) + 1;
+ }
+ return date;
+ }
+}, hasNegativeMonthYearBug);
+
+defineProperties(Date.prototype, {
+ toUTCString: function toUTCString() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var day = originalGetUTCDay(this);
+ var date = originalGetUTCDate(this);
+ var month = originalGetUTCMonth(this);
+ var year = originalGetUTCFullYear(this);
+ var hour = originalGetUTCHours(this);
+ var minute = originalGetUTCMinutes(this);
+ var second = originalGetUTCSeconds(this);
+ return dayName[day] + ', ' +
+ (date < 10 ? '0' + date : date) + ' ' +
+ monthName[month] + ' ' +
+ year + ' ' +
+ (hour < 10 ? '0' + hour : hour) + ':' +
+ (minute < 10 ? '0' + minute : minute) + ':' +
+ (second < 10 ? '0' + second : second) + ' GMT';
+ }
+}, hasNegativeMonthYearBug || hasToUTCStringFormatBug);
+
+// Opera 12 has `,`
+defineProperties(Date.prototype, {
+ toDateString: function toDateString() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var day = this.getDay();
+ var date = this.getDate();
+ var month = this.getMonth();
+ var year = this.getFullYear();
+ return dayName[day] + ' ' +
+ monthName[month] + ' ' +
+ (date < 10 ? '0' + date : date) + ' ' +
+ year;
+ }
+}, hasNegativeMonthYearBug || hasToDateStringFormatBug);
+
+// can't use defineProperties here because of toString enumeration issue in IE <= 8
+if (hasNegativeMonthYearBug || hasToStringFormatBug) {
+ Date.prototype.toString = function toString() {
+ if (!this || !(this instanceof Date)) {
+ throw new TypeError('this is not a Date object.');
+ }
+ var day = this.getDay();
+ var date = this.getDate();
+ var month = this.getMonth();
+ var year = this.getFullYear();
+ var hour = this.getHours();
+ var minute = this.getMinutes();
+ var second = this.getSeconds();
+ var timezoneOffset = this.getTimezoneOffset();
+ var hoursOffset = Math.floor(Math.abs(timezoneOffset) / 60);
+ var minutesOffset = Math.floor(Math.abs(timezoneOffset) % 60);
+ return dayName[day] + ' ' +
+ monthName[month] + ' ' +
+ (date < 10 ? '0' + date : date) + ' ' +
+ year + ' ' +
+ (hour < 10 ? '0' + hour : hour) + ':' +
+ (minute < 10 ? '0' + minute : minute) + ':' +
+ (second < 10 ? '0' + second : second) + ' GMT' +
+ (timezoneOffset > 0 ? '-' : '+') +
+ (hoursOffset < 10 ? '0' + hoursOffset : hoursOffset) +
+ (minutesOffset < 10 ? '0' + minutesOffset : minutesOffset);
+ };
+ if (supportsDescriptors) {
+ $Object.defineProperty(Date.prototype, 'toString', {
+ configurable: true,
+ enumerable: false,
+ writable: true
+ });
+ }
+}
+