2 var global = require('../internals/global');
3 var uncurryThis = require('../internals/function-uncurry-this');
4 var fails = require('../internals/fails');
5 var padStart = require('../internals/string-pad').start;
7 var RangeError = global.RangeError;
9 var DatePrototype = Date.prototype;
10 var n$DateToISOString = DatePrototype.toISOString;
11 var getTime = uncurryThis(DatePrototype.getTime);
12 var getUTCDate = uncurryThis(DatePrototype.getUTCDate);
13 var getUTCFullYear = uncurryThis(DatePrototype.getUTCFullYear);
14 var getUTCHours = uncurryThis(DatePrototype.getUTCHours);
15 var getUTCMilliseconds = uncurryThis(DatePrototype.getUTCMilliseconds);
16 var getUTCMinutes = uncurryThis(DatePrototype.getUTCMinutes);
17 var getUTCMonth = uncurryThis(DatePrototype.getUTCMonth);
18 var getUTCSeconds = uncurryThis(DatePrototype.getUTCSeconds);
20 // `Date.prototype.toISOString` method implementation
21 // https://tc39.es/ecma262/#sec-date.prototype.toisostring
22 // PhantomJS / old WebKit fails here:
23 module.exports = (fails(function () {
24 return n$DateToISOString.call(new Date(-5e13 - 1)) != '0385-07-25T07:06:39.999Z';
25 }) || !fails(function () {
26 n$DateToISOString.call(new Date(NaN));
27 })) ? function toISOString() {
28 if (!isFinite(getTime(this))) throw RangeError('Invalid time value');
30 var year = getUTCFullYear(date);
31 var milliseconds = getUTCMilliseconds(date);
32 var sign = year < 0 ? '-' : year > 9999 ? '+' : '';
33 return sign + padStart(abs(year), sign ? 6 : 4, 0) +
34 '-' + padStart(getUTCMonth(date) + 1, 2, 0) +
35 '-' + padStart(getUTCDate(date), 2, 0) +
36 'T' + padStart(getUTCHours(date), 2, 0) +
37 ':' + padStart(getUTCMinutes(date), 2, 0) +
38 ':' + padStart(getUTCSeconds(date), 2, 0) +
39 '.' + padStart(milliseconds, 3, 0) +
41 } : n$DateToISOString;