1 | 'use strict';
|
---|
2 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
3 | var fails = require('../internals/fails');
|
---|
4 | var padStart = require('../internals/string-pad').start;
|
---|
5 |
|
---|
6 | var $RangeError = RangeError;
|
---|
7 | var $isFinite = isFinite;
|
---|
8 | var abs = Math.abs;
|
---|
9 | var DatePrototype = Date.prototype;
|
---|
10 | var nativeDateToISOString = DatePrototype.toISOString;
|
---|
11 | var thisTimeValue = 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);
|
---|
19 |
|
---|
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 nativeDateToISOString.call(new Date(-5e13 - 1)) !== '0385-07-25T07:06:39.999Z';
|
---|
25 | }) || !fails(function () {
|
---|
26 | nativeDateToISOString.call(new Date(NaN));
|
---|
27 | })) ? function toISOString() {
|
---|
28 | if (!$isFinite(thisTimeValue(this))) throw new $RangeError('Invalid time value');
|
---|
29 | var date = this;
|
---|
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) +
|
---|
40 | 'Z';
|
---|
41 | } : nativeDateToISOString;
|
---|