21 Numbers and Dates

21.1 Number Objects

21.1.1 The Number Constructor

Number constructorは:

  • %Number%です。
  • global object"Number" propertyのinitial valueです。
  • constructorとして呼び出されたとき、新しいNumber objectを作成およびinitializeします。
  • constructorとしてではなくfunctionとして呼び出されたとき、type conversionを実行します。
  • class definitionのextends clauseのvalueとして使用できます。指定されたNumber behaviourをinheritしようとするsubclass constructorsは、[[NumberData]] internal slotを持つsubclass instanceを作成およびinitializeするために、Number constructorへのsuper callを含まなければなりません。

21.1.1.1 Number ( value )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. valueが存在するなら、
    1. primitiveを ? ToNumeric(value) とする。
    2. primitiveがBigIntなら、n𝔽((primitive))とする。
    3. そうでなければ、nprimitiveとする。
  2. そうでなければ、
    1. n+0𝔽とする。
  3. NewTargetがundefinedなら、nを返す。
  4. objを ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] ») とする。
  5. obj.[[NumberData]]nに設定する。
  6. objを返す。

21.1.2 Properties of the Number Constructor

Number constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

21.1.2.1 Number.EPSILON

Number.EPSILONのvalueは、1と、Number valueとしてrepresentableな1より大きい最小のvalueとの差のmagnitudeに対するNumber valueであり、およそ2.2204460492503130808472633361816 × 10-16です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.2 Number.isFinite ( number )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. numberがNumberでないなら、falseを返す。
  2. numberfiniteでないなら、falseを返す。
  3. trueを返す。

21.1.2.3 Number.isInteger ( number )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. numberintegral Numberなら、trueを返す。
  2. falseを返す。

21.1.2.4 Number.isNaN ( number )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. numberがNumberでないなら、falseを返す。
  2. numberNaNなら、trueを返す。
  3. falseを返す。
Note

このfunctionは、NaNであるかどうかをdetermineする前にそのargumentをNumberへconvertしないという点で、global isNaN function(19.2.3)とは異なります。

21.1.2.5 Number.isSafeInteger ( number )

Note

integer n は、nに対するNumber valueが他のどのintegerに対するNumber valueでもない場合に限り、“safe integer”です。

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. numberintegral Numberなら、
    1. abs((number)) ≤ 253 - 1なら、trueを返す。
  2. falseを返す。

21.1.2.6 Number.MAX_SAFE_INTEGER

Note

IEEE 754-2019のprecision limitationsによって必要とされるrounding behaviourのため、Number.MAX_SAFE_INTEGERより大きいすべてのintegerに対するNumber valueは、少なくとも1つの他のintegerとsharedされます。したがって、そのようなlarge-magnitude integerssafeではなく、Number valuesとして正確にrepresentableであること、または互いにdistinguishableであることすらguaranteeされません。例えば、90071992547409929007199254740993はいずれもNumber value 9007199254740992𝔽へevaluateされます。

Number.MAX_SAFE_INTEGERのvalueは9007199254740991𝔽𝔽(253 - 1))です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.7 Number.MAX_VALUE

Number.MAX_VALUEのvalueはNumber typeのlargest positive finite valueであり、およそ1.7976931348623157 × 10308です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.8 Number.MIN_SAFE_INTEGER

Note

IEEE 754-2019のprecision limitationsによって必要とされるrounding behaviourのため、Number.MIN_SAFE_INTEGERより小さいすべてのintegerに対するNumber valueは、少なくとも1つの他のintegerとsharedされます。したがって、そのようなlarge-magnitude integerssafeではなく、Number valuesとして正確にrepresentableであること、または互いにdistinguishableであることすらguaranteeされません。例えば、-9007199254740992-9007199254740993はいずれもNumber value -9007199254740992𝔽へevaluateされます。

Number.MIN_SAFE_INTEGERのvalueは-9007199254740991𝔽𝔽(-(253 - 1)))です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.9 Number.MIN_VALUE

Number.MIN_VALUEのvalueはNumber typeのsmallest positive valueであり、およそ5 × 10-324です。

IEEE 754-2019 double precision binary representationでは、smallest possible valueはdenormalized numberです。implementationがdenormalized valuesをsupportしない場合、Number.MIN_VALUEのvalueは、そのimplementationによって実際にrepresentできるsmallest non-zero positive valueでなければなりません。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.10 Number.NaN

Number.NaNのvalueはNaNです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.11 Number.NEGATIVE_INFINITY

Number.NEGATIVE_INFINITYのvalueは-∞𝔽です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.12 Number.parseFloat ( string )

"parseFloat" propertyのinitial valueは%parseFloat%です。

21.1.2.13 Number.parseInt ( string, radix )

"parseInt" propertyのinitial valueは%parseInt%です。

21.1.2.14 Number.POSITIVE_INFINITY

Number.POSITIVE_INFINITYのvalueは+∞𝔽です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.2.15 Number.prototype

Number.prototypeのinitial valueはNumber prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.1.3 Properties of the Number Prototype Object

Number prototype objectは:

  • %Number.prototype%です。
  • ordinary objectです。
  • それ自体がNumber objectです;valueが+0𝔽である[[NumberData]] internal slotを持ちます。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

明示的に別途述べられない限り、以下で定義されるNumber prototype objectのmethodsはgenericではなく、それらに渡されるthis valueは、Number valueであるか、Number valueへinitialize済みの[[NumberData]] internal slotを持つobjectでなければなりません。

methodのspecification内の“this Number value”というphraseは、method invocationのthis valueをargumentとして渡してabstract operation ThisNumberValueを呼び出した結果を指します。

21.1.3.1 Number.prototype.constructor

Number.prototype.constructorのinitial valueは%Number%です。

21.1.3.2 Number.prototype.toExponential ( fractionDigits )

このmethodは、this Number valueを、significandのdecimal pointの前に1桁、significandのdecimal pointの後にfractionDigits桁を持つdecimal exponential notationで表したStringを返します。fractionDigitsundefinedなら、Numberを一意に指定するために必要なだけのsignificand digitsを含めます(ToStringの場合と同様ですが、この場合Numberは常にexponential notationでoutputされる点が異なります)。

これは呼び出されたとき、次のstepsを実行します:

  1. numberを ? ThisNumberValue(this value) とする。
  2. fractionCountを ? ToIntegerOrInfinity(fractionDigits) とする。
  3. Assert: fractionDigitsundefinedなら、fractionCountは0である。
  4. numberfiniteでないなら、Number::toString(number, 10)を返す。
  5. fractionCount < 0またはfractionCount > 100なら、RangeError例外をthrowする。
  6. number(number)に設定する。
  7. signをempty Stringとする。
  8. number < 0なら、
    1. sign"-"に設定する。
    2. numberを-numberに設定する。
  9. number = 0なら、
    1. significandを、code unit 0x0030 (DIGIT ZERO)がfractionCount + 1回出現するString valueとする。
    2. exponentを0とする。
  10. そうでなければ、
    1. fractionDigitsundefinedでないなら、
      1. exponentおよびintSignificandを、10fractionCountintSignificand < 10fractionCount + 1であり、intSignificand × 10exponent - fractionCount - numberが可能な限りzeroに近くなるようなintegersとする。そのようなexponentおよびintSignificandのsetsが2つある場合、intSignificand × 10exponent - fractionCountがより大きい方のexponentおよびintSignificandを選ぶ。
    2. そうでなければ、
      1. exponentintSignificand、およびffを、ff ≥ 0、10ffintSignificand < 10ff + 1𝔽(intSignificand × 10exponent - ff)が𝔽(number)であり、ffが可能な限りsmallであるようなintegersとする。intSignificandのdecimal representationはff + 1 digitsを持ち、intSignificandは10で割り切れず、intSignificandのleast significant digitはこれらのcriteriaによって必ずしも一意にdeterminedされないことに注意。
      2. fractionCountffに設定する。
    3. significandを、intSignificandのdecimal representationのdigitsからなるString value(order通り、leading zeroesなし)とする。
  11. fractionCount ≠ 0なら、
    1. intPartsignificandの最初のcode unitとする。
    2. fractionalPartsignificandの他のfractionCount個のcode unitsとする。
    3. significandintPart"."、およびfractionalPartstring-concatenationに設定する。
  12. exponent = 0なら、
    1. exponentSign"+"とする。
    2. exponentDigits"0"とする。
  13. そうでなければ、
    1. exponent > 0なら、
      1. exponentSign"+"とする。
    2. そうでなければ、
      1. Assert: exponent < 0である。
      2. exponentSign"-"とする。
      3. exponentを-exponentに設定する。
    3. exponentDigitsを、exponentのdecimal representationのdigitsからなるString value(order通り、leading zeroesなし)とする。
  14. significandsignificand"e"exponentSign、およびexponentDigitsstring-concatenationに設定する。
  15. signsignificandstring-concatenationを返す。
Note

上記のrulesでrequiredされるよりもaccurateなconversionsを提供するimplementationsについては、step 10.b.iの次のalternative versionをguidelineとして使用することがrecommendedされます:

  1. exponentintSignificand、およびffを、ff ≥ 0、10ffintSignificand < 10ff + 1𝔽(intSignificand × 10exponent - ff)が𝔽(number)であり、ffが可能な限りsmallであるようなintegersとする。intSignificandについて複数のpossibilitiesがある場合、𝔽(intSignificand × 10exponent - ff)が𝔽(number)にclosestであるようにintSignificandを選ぶ。そのようなintSignificandのpossible valuesが2つある場合、evenである方を選ぶ。

21.1.3.3 Number.prototype.toFixed ( fractionDigits )

Note 1

このmethodは、this Number valueをdecimal fixed-point notationで表し、decimal pointの後にfractionDigits桁を持つStringを返します。fractionDigitsundefinedなら、0がassumedされます。

これは呼び出されたとき、次のstepsを実行します:

  1. numberを ? ThisNumberValue(this value) とする。
  2. fractionCountを ? ToIntegerOrInfinity(fractionDigits) とする。
  3. Assert: fractionDigitsundefinedなら、fractionCountは0である。
  4. fractionCountfiniteでないなら、RangeError例外をthrowする。
  5. fractionCount < 0またはfractionCount > 100なら、RangeError例外をthrowする。
  6. numberfiniteでないなら、Number::toString(number, 10)を返す。
  7. number(number)に設定する。
  8. signをempty Stringとする。
  9. number < 0なら、
    1. sign"-"に設定する。
    2. numberを-numberに設定する。
  10. number ≥ 1021なら、
    1. digitStringを ! ToString(𝔽(number)) とする。
  11. そうでなければ、
    1. intValueを、intValue / 10fractionCount - numberが可能な限りzeroに近くなるintegerとする。そのようなintValueが2つある場合、より大きいintValueを選ぶ。
    2. intValue = 0なら、digitString"0"とする;そうでなければ、digitStringintValueのdecimal representationのdigitsからなるString value(order通り、leading zeroesなし)とする。
    3. fractionCount ≠ 0なら、
      1. digitCountdigitStringのlengthとする。
      2. digitCountfractionCountなら、
        1. zeroPadを、code unit 0x0030 (DIGIT ZERO)がfractionCount + 1 - digitCount回出現するString valueとする。
        2. digitStringzeroPaddigitStringstring-concatenationに設定する。
        3. digitCountfractionCount + 1に設定する。
      3. intPartdigitStringの最初のdigitCount - fractionCount個のcode unitsとする。
      4. fractionalPartdigitStringの他のfractionCount個のcode unitsとする。
      5. digitStringintPart"."、およびfractionalPartstring-concatenationに設定する。
  12. signdigitStringstring-concatenationを返す。
Note 2

toFixedのoutputは、一部のvaluesについてtoStringよりもpreciseである場合があります。これは、toStringがnumberをadjacent Number valuesとdistinguishするのに十分なsignificant digitsだけをprintするためです。例えば、

(1000000000000000128).toString()"1000000000000000100"を返す一方、
(1000000000000000128).toFixed(0)"1000000000000000128"を返します。

21.1.3.4 Number.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodは、host environmentのcurrent localeのconventionsに従ってformattedされたthis Number valueを表すString valueをproduceします。このmethodはimplementation-definedであり、toStringと同じものを返すことはpermissibleですが、encouragedはされません。

このmethodのoptional parametersのmeaningsはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

21.1.3.5 Number.prototype.toPrecision ( precision )

このmethodは、this Number valueを、significandのdecimal pointの前に1桁、significandのdecimal pointの後にprecision - 1桁を持つdecimal exponential notation、またはprecision significant digitsを持つdecimal fixed notationのいずれかで表したStringを返します。precisionundefinedなら、代わりにToStringを呼び出します。

これは呼び出されたとき、次のstepsを実行します:

  1. numberを ? ThisNumberValue(this value) とする。
  2. precisionundefinedなら、! ToString(number)を返す。
  3. precisionCountを ? ToIntegerOrInfinity(precision) とする。
  4. numberfiniteでないなら、Number::toString(number, 10)を返す。
  5. precisionCount < 1またはprecisionCount > 100なら、RangeError例外をthrowする。
  6. number(number)に設定する。
  7. signをempty Stringとする。
  8. number < 0なら、
    1. signをcode unit 0x002D (HYPHEN-MINUS)に設定する。
    2. numberを-numberに設定する。
  9. number = 0なら、
    1. significandを、code unit 0x0030 (DIGIT ZERO)がprecisionCount回出現するString valueとする。
    2. exponentを0とする。
  10. そうでなければ、
    1. exponentおよびintSignificandを、10precisionCount - 1intSignificand < 10precisionCountであり、intSignificand × 10exponent - precisionCount + 1 - numberが可能な限りzeroに近くなるようなintegersとする。そのようなexponentおよびintSignificandのsetsが2つある場合、intSignificand × 10exponent - precisionCount + 1がより大きい方のexponentおよびintSignificandを選ぶ。
    2. significandを、intSignificandのdecimal representationのdigitsからなるString value(order通り、leading zeroesなし)とする。
    3. exponent < -6またはexponentprecisionCountなら、
      1. Assert: exponent ≠ 0である。
      2. precisionCount ≠ 1なら、
        1. intPartsignificandの最初のcode unitとする。
        2. fractionalPartsignificandの他のprecisionCount - 1個のcode unitsとする。
        3. significandintPart"."、およびfractionalPartstring-concatenationに設定する。
      3. exponent > 0なら、
        1. exponentSignをcode unit 0x002B (PLUS SIGN)とする。
      4. そうでなければ、
        1. Assert: exponent < 0である。
        2. exponentSignをcode unit 0x002D (HYPHEN-MINUS)とする。
        3. exponentを-exponentに設定する。
      5. exponentDigitsを、exponentのdecimal representationのdigitsからなるString value(order通り、leading zeroesなし)とする。
      6. signsignificand、code unit 0x0065 (LATIN SMALL LETTER E)、exponentSign、およびexponentDigitsstring-concatenationを返す。
  11. exponent = precisionCount - 1なら、signsignificandstring-concatenationを返す。
  12. exponent ≥ 0なら、
    1. significandを、significandの最初のexponent + 1個のcode units、code unit 0x002E (FULL STOP)、およびsignificandの残りのprecisionCount - (exponent + 1)個のcode unitsのstring-concatenationに設定する。
  13. そうでなければ、
    1. significandを、code unit 0x0030 (DIGIT ZERO)、code unit 0x002E (FULL STOP)、code unit 0x0030 (DIGIT ZERO)の-(exponent + 1)回のoccurrences、およびString significandstring-concatenationに設定する。
  14. signsignificandstring-concatenationを返す。

21.1.3.6 Number.prototype.toString ( [ radix ] )

Note

optional radixは、2𝔽から36𝔽までのinclusive interval内にあるintegral Number valueであるべきです。radixundefinedなら、10𝔽radixのvalueとして使用されます。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. xを ? ThisNumberValue(this value) とする。
  2. radixundefinedなら、radixMVを10とする。
  3. そうでなければ、radixMVを ? ToIntegerOrInfinity(radix) とする。
  4. radixMVが2から36までのinclusive interval内にないなら、RangeError例外をthrowする。
  5. Number::toString(x, radixMV)を返す。

このmethodはgenericではありません;そのthis valueがNumberまたはNumber objectでない場合、TypeError例外をthrowします。したがって、methodとして使用するために他の種類のobjectsへtransferすることはできません。

このmethodの"length" propertyは1𝔽です。

21.1.3.7 Number.prototype.valueOf ( )

  1. ThisNumberValue(this value)を返す。

21.1.3.7.1 ThisNumberValue ( arg )

The abstract operation ThisNumberValue takes argument arg (an ECMAScript language value) and returns either a normal completion containing a Number or a throw completion. It performs the following steps when called:

  1. argがNumberなら、argを返す。
  2. argがObjectであり、arg[[NumberData]] internal slotを持つなら、
    1. numberarg.[[NumberData]]とする。
    2. Assert: numberはNumberである。
    3. numberを返す。
  3. TypeError例外をThrowする。

21.1.4 Properties of Number Instances

Number instancesは、Number prototype objectからpropertiesをinheritするordinary objectsです。Number instancesはまた[[NumberData]] internal slotを持ちます。[[NumberData]] internal slotは、このNumber objectによって表されるNumber valueです。

21.2 BigInt Objects

21.2.1 The BigInt Constructor

BigInt constructorは:

  • %BigInt%です。
  • global object"BigInt" propertyのinitial valueです。
  • constructorとしてではなくfunctionとして呼び出されたとき、type conversionを実行します。
  • new operatorとともに使用すること、またはsubclassedされることを意図していません。class definitionのextends clauseのvalueとして使用できますが、BigInt constructorへのsuper callはexceptionを引き起こします。

21.2.1.1 BigInt ( value )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedでないなら、TypeError例外をthrowする。
  2. primitiveを ? ToPrimitive(value, number) とする。
  3. primitiveがNumberなら、? NumberToBigInt(primitive)を返す。
  4. ToBigInt(primitive)を返す。

21.2.1.1.1 NumberToBigInt ( number )

The abstract operation NumberToBigInt takes argument number (a Number) and returns either a normal completion containing a BigInt or a throw completion. It performs the following steps when called:

  1. numberintegral Numberでないなら、RangeError例外をthrowする。
  2. ((number))を返す。

21.2.2 Properties of the BigInt Constructor

BigInt constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • 次のpropertiesを持ちます:

21.2.2.1 BigInt.asIntN ( bits, bigint )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. bitsを? ToIndex(bits)に設定する。
  2. bigintを? ToBigInt(bigint)に設定する。
  3. (bigint) modulo 2bitsremainderとする。
  4. remainder ≥ 2bits - 1である場合、(remainder - 2bits)を返す。
  5. (remainder)を返す。

21.2.2.2 BigInt.asUintN ( bits, bigint )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. bitsを ? ToIndex(bits) に設定する。
  2. bigintを ? ToBigInt(bigint) に設定する。
  3. ((bigint) modulo 2bits)を返す。

21.2.2.3 BigInt.prototype

BigInt.prototypeのinitial valueはBigInt prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.2.3 Properties of the BigInt Prototype Object

BigInt prototype objectは:

  • %BigInt.prototype%です。
  • ordinary objectです。
  • BigInt objectではなく、[[BigIntData]] internal slotを持ちません。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

methodのspecification内の“this BigInt value”というphraseは、method invocationのthis valueをargumentとして渡してabstract operation ThisBigIntValueを呼び出した結果を指します。

21.2.3.1 BigInt.prototype.constructor

BigInt.prototype.constructorのinitial valueは%BigInt%です。

21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodは、host environmentのcurrent localeのconventionsに従ってformattedされたthis BigInt valueを表すString valueをproduceします。このmethodはimplementation-definedであり、toStringと同じものを返すことはpermissibleですが、encouragedはされません。

このmethodのoptional parametersのmeaningsはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

21.2.3.3 BigInt.prototype.toString ( [ radix ] )

Note

optional radixは、2𝔽から36𝔽までのinclusive interval内にあるintegral Number valueであるべきです。radixundefinedなら、10𝔽radixのvalueとして使用されます。

このmethodは呼び出されたとき、次のstepsを実行します:

  1. xを ? ThisBigIntValue(this value) とする。
  2. radixundefinedなら、radixMVを10とする。
  3. そうでなければ、radixMVを ? ToIntegerOrInfinity(radix) とする。
  4. radixMVが2から36までのinclusive interval内にないなら、RangeError例外をthrowする。
  5. BigInt::toString(x, radixMV)を返す。

このmethodはgenericではありません;そのthis valueがBigIntまたはBigInt objectでない場合、TypeError例外をthrowします。したがって、methodとして使用するために他の種類のobjectsへtransferすることはできません。

21.2.3.4 BigInt.prototype.valueOf ( )

  1. ThisBigIntValue(this value)を返す。

21.2.3.4.1 ThisBigIntValue ( arg )

The abstract operation ThisBigIntValue takes argument arg (an ECMAScript language value) and returns either a normal completion containing a BigInt or a throw completion. It performs the following steps when called:

  1. argがBigIntなら、argを返す。
  2. argがObjectであり、arg[[BigIntData]] internal slotを持つなら、
    1. Assert: arg.[[BigIntData]]はBigIntである。
    2. arg.[[BigIntData]]を返す。
  3. TypeError例外をThrowする。

21.2.3.5 BigInt.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "BigInt"です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

21.2.4 Properties of BigInt Instances

BigInt instancesは、BigInt prototype objectからpropertiesをinheritするordinary objectsです。BigInt instancesはまた[[BigIntData]] internal slotを持ちます。[[BigIntData]] internal slotは、このBigInt objectによって表されるBigInt valueです。

21.3 The Math Object

Math objectは:

  • %Math%です。
  • global object"Math" propertyのinitial valueです。
  • ordinary objectです。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。
  • function objectではありません。
  • [[Construct]] internal methodを持ちません;new operatorを伴うconstructorとして使用できません。
  • [[Call]] internal methodを持ちません;functionとして呼び出せません。
Note

この仕様では、“the Number value for x”というphraseは、6.1.6.1で定義されるtechnical meaningを持ちます。

21.3.1 Value Properties of the Math Object

21.3.1.1 Math.E

e、すなわちnatural logarithmsのbaseに対するNumber valueであり、およそ2.7182818284590452354です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.3.1.2 Math.LN10

10のnatural logarithmに対するNumber valueであり、およそ2.302585092994046です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.3.1.3 Math.LN2

2のnatural logarithmに対するNumber valueであり、およそ0.6931471805599453です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.3.1.4 Math.LOG10E

e、すなわちnatural logarithmsのbaseのbase-10 logarithmに対するNumber valueです;このvalueはおよそ0.4342944819032518です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

Note

Math.LOG10EのvalueはMath.LN10のvalueのreciprocalにおおよそ等しいです。

21.3.1.5 Math.LOG2E

e、すなわちnatural logarithmsのbaseのbase-2 logarithmに対するNumber valueです;このvalueはおよそ1.4426950408889634です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

Note

Math.LOG2EのvalueはMath.LN2のvalueのreciprocalにおおよそ等しいです。

21.3.1.6 Math.PI

π、すなわちcircleのcircumferenceとdiameterのratioに対するNumber valueであり、およそ3.1415926535897932です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.3.1.7 Math.SQRT1_2

½のsquare rootに対するNumber valueであり、およそ0.7071067811865476です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

Note

Math.SQRT1_2のvalueはMath.SQRT2のvalueのreciprocalにおおよそ等しいです。

21.3.1.8 Math.SQRT2

2のsquare rootに対するNumber valueであり、およそ1.4142135623730951です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.3.1.9 Math [ %Symbol.toStringTag% ]

%Symbol.toStringTag% propertyのinitial valueはString value "Math"です。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

21.3.2 Function Properties of the Math Object

Note

functions acosacoshasinasinhatanatanhatan2cbrtcoscoshexpexpm1hypotloglog1plog2log10powrandomsinsinhtan、およびtanhのbehaviourは、interestのあるboundary casesを表す特定のargument valuesに対してspecific resultsをrequireすることを除き、ここではpreciselyに指定されません。他のargument valuesについては、これらのfunctionsはfamiliar mathematical functionsのresultsへのapproximationsをcomputeすることを意図していますが、approximation algorithmsの選択にはある程度のlatitudeが許されます。general intentは、implementerが、与えられたhardware platform上のECMAScriptに対して、そのplatform上のC programmersが利用できる同じmathematical libraryを使用できるようにすることです。

algorithmsの選択はimplementationに任されますが、implementationsは、Sun Microsystemsのfreely distributable mathematical libraryであるfdlibmhttp://www.netlib.org/fdlibm)に含まれるIEEE 754-2019 arithmetic用のapproximation algorithmsを使用することがrecommendedされます(ただしこのstandardによって指定されるものではありません)。

21.3.2.1 Math.abs ( x )

このfunctionはxのabsolute valueを返します;resultはxと同じmagnitudeを持ちますが、positive signを持ちます。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNなら、NaNを返す。
  3. n-0𝔽なら、+0𝔽を返す。
  4. n-∞𝔽なら、+∞𝔽を返す。
  5. n < -0𝔽なら、-nを返す。
  6. nを返す。

21.3.2.2 Math.acos ( x )

このfunctionはxのinverse cosineを返します。resultはradiansで表され、+0𝔽から𝔽(π)までのinclusive interval内にあります。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNn > 1𝔽、またはn < -1𝔽のいずれかなら、NaNを返す。
  3. n1𝔽なら、+0𝔽を返す。
  4. (n)のinverse cosineを表すimplementation-approximated Number valueを返す。

21.3.2.3 Math.acosh ( x )

このfunctionはxのinverse hyperbolic cosineを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNまたは+∞𝔽のいずれかなら、nを返す。
  3. n1𝔽なら、+0𝔽を返す。
  4. n < 1𝔽なら、NaNを返す。
  5. (n)のinverse hyperbolic cosineを表すimplementation-approximated Number valueを返す。

21.3.2.4 Math.asin ( x )

このfunctionはxのinverse sineを返します。resultはradiansで表され、𝔽(-π / 2)から𝔽(π / 2)までのinclusive interval内にあります。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n > 1𝔽またはn < -1𝔽なら、NaNを返す。
  4. (n)のinverse sineを表すimplementation-approximated Number valueを返す。

21.3.2.5 Math.asinh ( x )

このfunctionはxのinverse hyperbolic sineを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはn+0𝔽または-0𝔽のいずれかなら、nを返す。
  3. (n)のinverse hyperbolic sineを表すimplementation-approximated Number valueを返す。

21.3.2.6 Math.atan ( x )

このfunctionはxのinverse tangentを返します。resultはradiansで表され、𝔽(-π / 2)から𝔽(π / 2)までのinclusive interval内にあります。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n+∞𝔽なら、π / 2を表すimplementation-approximated Number valueを返す。
  4. n-∞𝔽なら、-π / 2を表すimplementation-approximated Number valueを返す。
  5. (n)のinverse tangentを表すimplementation-approximated Number valueを返す。

21.3.2.7 Math.atanh ( x )

このfunctionはxのinverse hyperbolic tangentを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n > 1𝔽またはn < -1𝔽なら、NaNを返す。
  4. n1𝔽なら、+∞𝔽を返す。
  5. n-1𝔽なら、-∞𝔽を返す。
  6. (n)のinverse hyperbolic tangentを表すimplementation-approximated Number valueを返す。

21.3.2.8 Math.atan2 ( y, x )

このfunctionはarguments yおよびxのquotient y / xのinverse tangentを返します。ここで、yおよびxのsignsはresultのquadrantをdetermineするために使用されます。2-argument inverse tangent functionでは、yという名前のargumentがfirstで、xという名前のargumentがsecondであることはintentionalかつtraditionalであることに注意してください。resultはradiansで表され、-πから+πまでのinclusive interval内にあります。

これは呼び出されたとき、次のstepsを実行します:

  1. nyを ? ToNumber(y) とする。
  2. nxを ? ToNumber(x) とする。
  3. nyNaNまたはnxNaNなら、NaNを返す。
  4. ny+∞𝔽なら、
    1. nx+∞𝔽なら、π / 4を表すimplementation-approximated Number valueを返す。
    2. nx-∞𝔽なら、3π / 4を表すimplementation-approximated Number valueを返す。
    3. π / 2を表すimplementation-approximated Number valueを返す。
  5. ny-∞𝔽なら、
    1. nx+∞𝔽なら、-π / 4を表すimplementation-approximated Number valueを返す。
    2. nx-∞𝔽なら、-3π / 4を表すimplementation-approximated Number valueを返す。
    3. -π / 2を表すimplementation-approximated Number valueを返す。
  6. ny+0𝔽なら、
    1. nx > +0𝔽またはnx+0𝔽なら、+0𝔽を返す。
    2. πを表すimplementation-approximated Number valueを返す。
  7. ny-0𝔽なら、
    1. nx > +0𝔽またはnx+0𝔽なら、-0𝔽を返す。
    2. -πを表すimplementation-approximated Number valueを返す。
  8. Assert: nyfiniteであり、+0𝔽でも-0𝔽でもない。
  9. ny > +0𝔽なら、
    1. nx+∞𝔽なら、+0𝔽を返す。
    2. nx-∞𝔽なら、πを表すimplementation-approximated Number valueを返す。
    3. nx+0𝔽または-0𝔽のいずれかなら、π / 2を表すimplementation-approximated Number valueを返す。
  10. ny < -0𝔽なら、
    1. nx+∞𝔽なら、-0𝔽を返す。
    2. nx-∞𝔽なら、-πを表すimplementation-approximated Number valueを返す。
    3. nx+0𝔽または-0𝔽のいずれかなら、-π / 2を表すimplementation-approximated Number valueを返す。
  11. Assert: nxfiniteであり、+0𝔽でも-0𝔽でもない。
  12. resultabs((ny) / (nx))のinverse tangentとする。
  13. nx < -0𝔽なら、
    1. ny > +0𝔽なら、resultをπ - resultに設定する。
    2. そうでなければ、resultを-π + resultに設定する。
  14. そうでなければ、
    1. ny < -0𝔽なら、resultを-resultに設定する。
  15. resultを表すimplementation-approximated Number valueを返す。

21.3.2.9 Math.cbrt ( x )

このfunctionはxのcube rootを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはn+0𝔽または-0𝔽のいずれかなら、nを返す。
  3. (n)のcube rootを表すimplementation-approximated Number valueを返す。

21.3.2.10 Math.ceil ( x )

このfunctionは、x以上であるsmallest(-∞にclosest)integral Number valueを返します。xがすでにintegral Numberである場合、resultはxです。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはn+0𝔽または-0𝔽のいずれかなら、nを返す。
  3. n < -0𝔽かつn > -1𝔽なら、-0𝔽を返す。
  4. nintegral Numberなら、nを返す。
  5. n以上であるsmallest(-∞にclosest)integral Number valueを返す。
Note

Math.ceil(x)のvalueは-Math.floor(-x)のvalueと同じです。

21.3.2.11 Math.clz32 ( x )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToUint32(x) とする。
  2. pnのunsigned 32-bit binary representationにおけるleading zero bitsの数とする。
  3. 𝔽(p)を返す。
Note

n+0𝔽または-0𝔽のいずれかである場合、このmethodは32𝔽を返します。nの32-bit binary encodingのmost significant bitが1である場合、このmethodは+0𝔽を返します。

21.3.2.12 Math.cos ( x )

このfunctionはxのcosineを返します。argumentはradiansで表されます。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでないなら、NaNを返す。
  3. n+0𝔽または-0𝔽のいずれかなら、1𝔽を返す。
  4. (n)のcosineを表すimplementation-approximated Number valueを返す。

21.3.2.13 Math.cosh ( x )

このfunctionはxのhyperbolic cosineを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNなら、NaNを返す。
  3. n+∞𝔽または-∞𝔽のいずれかなら、+∞𝔽を返す。
  4. n+0𝔽または-0𝔽のいずれかなら、1𝔽を返す。
  5. (n)のhyperbolic cosineを表すimplementation-approximated Number valueを返す。
Note

Math.cosh(x)のvalueは(Math.exp(x) + Math.exp(-x)) / 2のvalueと同じです。

21.3.2.14 Math.exp ( x )

このfunctionはxのexponential function(ex乗したもの。ここでeはnatural logarithmsのbase)を返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNまたは+∞𝔽のいずれかなら、nを返す。
  3. n+0𝔽または-0𝔽のいずれかなら、1𝔽を返す。
  4. n-∞𝔽なら、+0𝔽を返す。
  5. (n)のexponential functionを表すimplementation-approximated Number valueを返す。

21.3.2.15 Math.expm1 ( x )

このfunctionはxのexponential function(ex乗したもの。ここでeはnatural logarithmsのbase)から1をsubtractしたresultを返します。resultは、xのvalueが0に近い場合でもaccurateになるようにcomputedされます。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽-0𝔽、または+∞𝔽のいずれかなら、nを返す。
  3. n-∞𝔽なら、-1𝔽を返す。
  4. exp(n)のexponential functionとする。
  5. exp - 1を表すimplementation-approximated Number valueを返す。

21.3.2.16 Math.floor ( x )

このfunctionは、x以下であるgreatest(+∞にclosest)integral Number valueを返します。xがすでにintegral Numberである場合、resultはxです。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはn+0𝔽または-0𝔽のいずれかなら、nを返す。
  3. n < 1𝔽かつn > +0𝔽なら、+0𝔽を返す。
  4. nintegral Numberなら、nを返す。
  5. n以下であるgreatest(+∞にclosest)integral Number valueを返す。
Note

Math.floor(x)のvalueは-Math.ceil(-x)のvalueと同じです。

21.3.2.17 Math.fround ( x )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNなら、NaNを返す。
  3. n+0𝔽-0𝔽+∞𝔽、または-∞𝔽のいずれかなら、nを返す。
  4. n32を、roundTiesToEven modeを使用してnIEEE 754-2019 binary32 formatへconvertしたresultとする。
  5. n64を、n32IEEE 754-2019 binary64 formatへconvertしたresultとする。
  6. n64に対応するECMAScript Number valueを返す。

21.3.2.18 Math.f16round ( x )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNなら、NaNを返す。
  3. n+0𝔽-0𝔽+∞𝔽、または-∞𝔽のいずれかなら、nを返す。
  4. n16を、roundTiesToEven modeを使用してnIEEE 754-2019 binary16 formatへconvertしたresultとする。
  5. n64を、n16IEEE 754-2019 binary64 formatへconvertしたresultとする。
  6. n64に対応するECMAScript Number valueを返す。
Note

このoperationは、binary32へcastしてからbinary16へcastすることと同じではありません。double-roundingの可能性があるためです:例えばnumber k = 1.00048828125000022204𝔽を考えると、Math.f16round(k)は1.0009765625𝔽ですが、Math.f16round(Math.fround(k))は1𝔽です。

すべてのplatformsがbinary64からbinary16へのcastingにnative supportを提供するわけではありません。これを提供できるlibrariesはさまざまあり、MIT-licensedのhalf libraryも含まれます。あるいは、まずroundTiesToEvenの下でbinary64からbinary32へcastし、そのresultがincorrect double-roundingにつながる可能性があるかどうかをcheckすることもできます。そのようなcasesは、binary32 valueのmantissaをadjustし、initial castをroundTiesToOddの下で実行した場合にproduceされるvalueになるようにすることで明示的にhandleできます。adjusted valueをroundTiesToEvenの下でbinary16へcastすると、correct valueがproduceされます。

21.3.2.19 Math.hypot ( ...args )

zero以上のargumentsが与えられると、このfunctionはそのargumentsのsquaresのsumのsquare rootを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. coercedを新しい空のListとする。
  2. argsの各要素argについて、以下を行う
    1. nを ? ToNumber(arg) とする。
    2. ncoercedへappendする。
  3. coercedの各要素numberについて、以下を行う
    1. number+∞𝔽または-∞𝔽のいずれかなら、+∞𝔽を返す。
  4. onlyZerotrueとする。
  5. coercedの各要素numberについて、以下を行う
    1. numberNaNなら、NaNを返す。
    2. number+0𝔽でも-0𝔽でもないなら、onlyZerofalseに設定する。
  6. onlyZerotrueなら、+0𝔽を返す。
  7. coercedの要素のmathematical valuesのsquaresのsumのsquare rootを表すimplementation-approximated Number valueを返す。

このfunctionの"length" propertyは2𝔽です。

Note

このfunctionが2つ以上のargumentsで呼び出されるときにnaive implementationsで発生しやすいoverflowsおよびunderflowsによるprecision lossを避けるよう、implementationsは注意すべきです。

21.3.2.20 Math.imul ( x, y )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. a(? ToUint32(x))とする。
  2. b(? ToUint32(y))とする。
  3. productを(a × b) modulo 232とする。
  4. product ≥ 231なら、𝔽(product - 232)を返す。
  5. 𝔽(product)を返す。

21.3.2.21 Math.log ( x )

このfunctionはxのnatural logarithmを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNまたは+∞𝔽のいずれかなら、nを返す。
  3. n1𝔽なら、+0𝔽を返す。
  4. n+0𝔽または-0𝔽のいずれかなら、-∞𝔽を返す。
  5. n < -0𝔽なら、NaNを返す。
  6. ln((n))を表すimplementation-approximated Number valueを返す。

21.3.2.22 Math.log1p ( x )

このfunctionは1 + xのnatural logarithmを返します。resultは、xのvalueがzeroに近い場合でもaccurateになるようにcomputedされます。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽-0𝔽、または+∞𝔽のいずれかなら、nを返す。
  3. n-1𝔽なら、-∞𝔽を返す。
  4. n < -1𝔽なら、NaNを返す。
  5. ln(1 + (n))を表すimplementation-approximated Number valueを返す。

21.3.2.23 Math.log10 ( x )

このfunctionはxのbase 10 logarithmを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNまたは+∞𝔽のいずれかなら、nを返す。
  3. n1𝔽なら、+0𝔽を返す。
  4. n+0𝔽または-0𝔽のいずれかなら、-∞𝔽を返す。
  5. n < -0𝔽なら、NaNを返す。
  6. log10((n))を表すimplementation-approximated Number valueを返す。

21.3.2.24 Math.log2 ( x )

このfunctionはxのbase 2 logarithmを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaNまたは+∞𝔽のいずれかなら、nを返す。
  3. n1𝔽なら、+0𝔽を返す。
  4. n+0𝔽または-0𝔽のいずれかなら、-∞𝔽を返す。
  5. n < -0𝔽なら、NaNを返す。
  6. log2((n))を表すimplementation-approximated Number valueを返す。

21.3.2.25 Math.max ( ...args )

zero以上のargumentsが与えられると、このfunctionはargumentsのそれぞれにToNumberをcallし、得られたvaluesのlargestを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. coercedを新しい空のListとする。
  2. argsの各要素argについて、以下を行う
    1. nを ? ToNumber(arg) とする。
    2. ncoercedへappendする。
  3. highest-∞𝔽とする。
  4. coercedの各要素numberについて、以下を行う
    1. numberNaNなら、NaNを返す。
    2. number+0𝔽であり、highest-0𝔽なら、highest+0𝔽に設定する。
    3. number > highestなら、highestnumberに設定する。
  5. highestを返す。
Note

largest valueをdetermineするためのvaluesのcomparisonは、+0𝔽-0𝔽より大きいとみなされることを除き、IsLessThan algorithmを使用して行われます。

このfunctionの"length" propertyは2𝔽です。

21.3.2.26 Math.min ( ...args )

zero以上のargumentsが与えられると、このfunctionはargumentsのそれぞれにToNumberをcallし、得られたvaluesのsmallestを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. coercedを新しい空のListとする。
  2. argsの各要素argについて、以下を行う
    1. nを ? ToNumber(arg) とする。
    2. ncoercedへappendする。
  3. lowest+∞𝔽とする。
  4. coercedの各要素numberについて、以下を行う
    1. numberNaNなら、NaNを返す。
    2. number-0𝔽であり、lowest+0𝔽なら、lowest-0𝔽に設定する。
    3. number < lowestなら、lowestnumberに設定する。
  5. lowestを返す。
Note

smallest valueをdetermineするためのvaluesのcomparisonは、+0𝔽-0𝔽より大きいとみなされることを除き、IsLessThan algorithmを使用して行われます。

このfunctionの"length" propertyは2𝔽です。

21.3.2.27 Math.pow ( base, exponent )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. baseを ? ToNumber(base) に設定する。
  2. exponentを ? ToNumber(exponent) に設定する。
  3. Number::exponentiate(base, exponent)を返す。

21.3.2.28 Math.random ( )

このfunctionは、positive signを持ち、+0𝔽以上かつ1𝔽未満であり、そのrange上でおおよそuniform distributionに従ってrandomlyまたはpseudo randomlyに選ばれたNumber valueを、implementation-defined algorithmまたはstrategyを使用して返します。

distinct realmsに対して作成された各Math.random functionは、successive callsからdistinct sequence of valuesをproduceしなければなりません。

21.3.2.29 Math.round ( x )

このfunctionは、xにclosestでありintegralであるNumber valueを返します。2つのintegral Numbersxにequally closeである場合、resultは+∞にcloserなNumber valueです。xがすでにintegralである場合、resultはxです。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはnintegral Numberなら、nを返す。
  3. n < 0.5𝔽かつn > +0𝔽なら、+0𝔽を返す。
  4. n < -0𝔽かつn-0.5𝔽なら、-0𝔽を返す。
  5. nにclosestなintegral Numberを返し、tieの場合は+∞にcloserなNumberを優先する。
Note 1

Math.round(3.5)は4を返しますが、Math.round(-3.5)は-3を返します。

Note 2

Math.round(x)のvalueは、常にMath.floor(x + 0.5)のvalueと同じとは限りません。x-0𝔽である場合、またはx-0𝔽より小さく、かつ-0.5𝔽以上である場合、Math.round(x)-0𝔽を返しますが、Math.floor(x + 0.5)+0𝔽を返します。Math.round(x)はまた、x + 0.5をcomputeするときのinternal roundingのため、Math.floor(x + 0.5)のvalueと異なる場合があります。

21.3.2.30 Math.sign ( x )

このfunctionはxのsignを返し、xがpositive、negative、またはzeroであるかを示します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n < -0𝔽なら、-1𝔽を返す。
  4. 1𝔽を返す。

21.3.2.31 Math.sin ( x )

このfunctionはxのsineを返します。argumentはradiansで表されます。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n+∞𝔽または-∞𝔽のいずれかなら、NaNを返す。
  4. (n)のsineを表すimplementation-approximated Number valueを返す。

21.3.2.32 Math.sinh ( x )

このfunctionはxのhyperbolic sineを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはn+0𝔽または-0𝔽のいずれかなら、nを返す。
  3. (n)のhyperbolic sineを表すimplementation-approximated Number valueを返す。
Note

Math.sinh(x)のvalueは(Math.exp(x) - Math.exp(-x)) / 2のvalueと同じです。

21.3.2.33 Math.sqrt ( x )

このfunctionはxのsquare rootを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽-0𝔽、または+∞𝔽のいずれかなら、nを返す。
  3. n < -0𝔽なら、NaNを返す。
  4. 𝔽((n)のsquare root)を返す。

21.3.2.34 Math.sumPrecise ( items )

Numbersのiterableが与えられると、このfunctionはiterable内の各valueをsumし、それらのsumを返します。何らかのvalueがNumberでない場合、TypeError例外をthrowします。

これは呼び出されたとき、次のstepsを実行します:

  1. RequireObjectCoercible(items)を実行する。
  2. iteratorRecordを ? GetIterator(items, sync) とする。
  3. stateminus-zeroとする。
  4. sumを0とする。
  5. countを0とする。
  6. nextnot-startedとする。
  7. nextdoneでない間、繰り返す
    1. nextを ? IteratorStepValue(iteratorRecord) に設定する。
    2. nextdoneでないなら、
      1. count ≥ 253 - 1なら、
        1. NOTE: このstepは実際には到達しないことが期待されており、implementationsがこの仕様に違反することなくinputsが“reasonably sized”であることに依存できるようにするためだけに含まれる。
        2. errorThrowCompletion(a newly created RangeError object)とする。
        3. IteratorClose(iteratorRecord, error)を返す。
      2. nextがNumberでないなら、
        1. errorThrowCompletion(a newly created TypeError object)とする。
        2. IteratorClose(iteratorRecord, error)を返す。
      3. nnextとする。
      4. statenot-a-numberでないなら、
        1. nNaNなら、
          1. statenot-a-numberに設定する。
        2. そうでなく、n+∞𝔽なら、
          1. stateminus-infinityなら、statenot-a-numberに設定する。
          2. そうでなければ、stateplus-infinityに設定する。
        3. そうでなく、n-∞𝔽なら、
          1. stateplus-infinityなら、statenot-a-numberに設定する。
          2. そうでなければ、stateminus-infinityに設定する。
        4. そうでなく、n-0𝔽でなく、かつstateminus-zeroまたはfiniteのいずれかなら、
          1. statefiniteに設定する。
          2. sumsum + (n)に設定する。
      5. countcount + 1に設定する。
  8. statenot-a-numberなら、NaNを返す。
  9. stateplus-infinityなら、+∞𝔽を返す。
  10. stateminus-infinityなら、-∞𝔽を返す。
  11. stateminus-zeroなら、-0𝔽を返す。
  12. 𝔽(sum)を返す。
Note

sumのvalueは、さまざまなalgorithmsによってarbitrary-precision arithmeticなしでcomputedできます。その1つは、Jonathan Richard ShewchukによるAdaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicatesに示されている“Grow-Expansion” algorithmです。よりrecentなalgorithmは“Fast exact summation using small and large superaccumulators”に示されており、そのcodeはhttps://gitlab.com/radfordneal/xsumで利用できます。

21.3.2.35 Math.tan ( x )

このfunctionはxのtangentを返します。argumentはradiansで表されます。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n+∞𝔽または-∞𝔽のいずれかなら、NaNを返す。
  4. (n)のtangentを表すimplementation-approximated Number valueを返す。

21.3.2.36 Math.tanh ( x )

このfunctionはxのhyperbolic tangentを返します。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nNaN+0𝔽、または-0𝔽のいずれかなら、nを返す。
  3. n+∞𝔽なら、1𝔽を返す。
  4. n-∞𝔽なら、-1𝔽を返す。
  5. (n)のhyperbolic tangentを表すimplementation-approximated Number valueを返す。
Note

Math.tanh(x)のvalueは(Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x))のvalueと同じです。

21.3.2.37 Math.trunc ( x )

このfunctionはnumber xのintegral partを返し、fractional digitsをremoveします。xがすでにintegralである場合、resultはxです。

これは呼び出されたとき、次のstepsを実行します:

  1. nを ? ToNumber(x) とする。
  2. nfiniteでない、またはn+0𝔽または-0𝔽のいずれかなら、nを返す。
  3. n < 1𝔽かつn > +0𝔽なら、+0𝔽を返す。
  4. n < -0𝔽かつn > -1𝔽なら、-0𝔽を返す。
  5. +0𝔽の方向にnにnearestなintegral Numberを返す。

21.4 Date Objects

21.4.1 Overview of Date Objects and Definitions of Abstract Operations

以下のabstract operationstime values21.4.1.1で定義)に対してoperateします。いずれの場合も、これらのfunctionsのいずれかへの任意のargumentがNaNである場合、resultはNaNになります。

21.4.1.1 Time Values and Time Range

ECMAScriptにおけるtime measurementはPOSIXにおけるtime measurementに類似しており、特にproleptic Gregorian calendar、1970年1月1日UTCの開始時のmidnightをepochとすること、およびすべての日を正確に86,400秒(各秒は1000 milliseconds)から構成されるものとしてaccountingすることによるdefinitionを共有します。

ECMAScriptのtime valueはNumberであり、millisecond precisionでtime内のinstantを表すfinite integral Number、またはspecific instantを表さないNaNのいずれかです。24 × 60 × 60 × 1000 = 86,400,000のmultipleであるtime value(すなわち、あるinteger dについて86,400,000 × dであるもの)は、epochからd whole UTC days後(negative dではepochより前)に続くUTC dayのstartのinstantを表します。他のすべてのfinite time value tvは、そのようなmultipleであるgreatest preceding time value sにrelativeに定義され、sと同じUTC day内で発生し、(tv - s) millisecondsだけ後に続くinstantを表します。

Time valuesはUTC leap secondsをaccountしません—positive leap seconds内のinstantsを表すtime valuesは存在せず、negative leap secondsによってUTC timelineからremovedされたinstantsを表すtime valuesが存在します。しかしながら、time valuesのdefinitionは、それにもかかわらずUTCとのpiecewise alignmentをもたらし、discontinuitiesはleap second boundariesにのみ存在し、leap secondsの外側ではzero differenceになります。

Numberは-9,007,199,254,740,992から9,007,199,254,740,992までのすべてのintegersをexactlyにrepresentできます(21.1.2.8および21.1.2.6)。time valueは、-8,640,000,000,000,000から8,640,000,000,000,000 millisecondsまでのやや小さいrangeをsupportします。これにより、1970年1月1日UTCの開始時のmidnightを基準として、正確に-100,000,000 daysから100,000,000 daysまでのsupported time value rangeが得られます。

1970年1月1日UTCの開始時のmidnightのexact momentは、time value +0𝔽によって表されます。

Note

proleptic Gregorian calendarでは、leap yearsは、4でdivisibleであり、かつ400でdivisibleであるか100でdivisibleでないものです。

proleptic Gregorian calendarの400 year cycleには97 leap yearsが含まれます。これにより、yearあたり平均365.2425 days、すなわち31,556,952,000 millisecondsになります。したがって、Numberがmillisecond precisionでexactlyにrepresentできるmaximum rangeは、1970年を基準としておよそ-285,426年から285,426年です。このsectionで指定されるtime valueによってsupportされるsmaller rangeは、1970年を基準としておよそ-273,790年から273,790年です。

21.4.1.2 Time-related Constants

これらのconstantsは、以下のsectionsのalgorithmsによって参照されます。

HoursPerDay = 24
MinutesPerHour = 60
SecondsPerMinute = 60
msPerSecond = 1000𝔽
msPerMinute = 60000𝔽 = msPerSecond × 𝔽(SecondsPerMinute)
msPerHour = 3600000𝔽 = msPerMinute × 𝔽(MinutesPerHour)
msPerDay = 86400000𝔽 = msPerHour × 𝔽(HoursPerDay)

21.4.1.3 Day ( tv )

The abstract operation Day takes argument tv (a finite time value) and returns an integral Number. tvが属するdayのday numberを返します。 It performs the following steps when called:

  1. 𝔽(floor((tv / msPerDay)))を返す。

21.4.1.4 TimeWithinDay ( tv )

The abstract operation TimeWithinDay takes argument tv (a finite time value) and returns an integral Number in the interval from +0𝔽 (inclusive) to msPerDay (exclusive). tvが属するdayのstartからのmillisecondsの数を返します。 It performs the following steps when called:

  1. 𝔽((tv) modulo (msPerDay))を返す。

21.4.1.5 DaysInYear ( y )

The abstract operation DaysInYear takes argument y (an integral Number) and returns 365𝔽 or 366𝔽. year yに含まれるdaysの数を返します。Leap yearsは366 daysを持ちます;他のすべてのyearsは365です。 It performs the following steps when called:

  1. ry(y)とする。
  2. (ry modulo 400) = 0なら、366𝔽を返す。
  3. (ry modulo 100) = 0なら、365𝔽を返す。
  4. (ry modulo 4) = 0なら、366𝔽を返す。
  5. 365𝔽を返す。

21.4.1.6 DayFromYear ( y )

The abstract operation DayFromYear takes argument y (an integral Number) and returns an integral Number. year yのfirst dayのday numberを返します。 It performs the following steps when called:

  1. ry(y)とする。
  2. NOTE: 以下のstepsでは、numberYears1numberYears4numberYears100、およびnumberYears400は、それぞれepochとyear yのstartとの間に現れる、1、4、100、および400でdivisibleなyearsの数を表す。yepochより前なら、この数はnegativeである。
  3. numberYears1を(ry - 1970)とする。
  4. numberYears4floor((ry - 1969) / 4)とする。
  5. numberYears100floor((ry - 1901) / 100)とする。
  6. numberYears400floor((ry - 1601) / 400)とする。
  7. 𝔽(365 × numberYears1 + numberYears4 - numberYears100 + numberYears400)を返す。

21.4.1.7 TimeFromYear ( y )

The abstract operation TimeFromYear takes argument y (an integral Number) and returns a time value. year yのstartのtime valueを返します。 It performs the following steps when called:

  1. msPerDay × DayFromYear(y)を返す。

21.4.1.8 YearFromTime ( tv )

The abstract operation YearFromTime takes argument tv (a finite time value) and returns an integral Number. tvが属するyearを返します。 It performs the following steps when called:

  1. TimeFromYear(y) ≤ tvであるようなlargest integral Number y(+∞にclosest)を返す。

21.4.1.9 DayWithinYear ( tv )

The abstract operation DayWithinYear takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 365𝔽. It performs the following steps when called:

  1. Day(tv) - DayFromYear(YearFromTime(tv))を返す。

21.4.1.10 InLeapYear ( tv )

The abstract operation InLeapYear takes argument tv (a finite time value) and returns +0𝔽 or 1𝔽. tvがleap year内にある場合は1𝔽を返し、そうでなければ+0𝔽を返します。 It performs the following steps when called:

  1. DaysInYear(YearFromTime(tv))が366𝔽なら、1𝔽を返す。
  2. +0𝔽を返す。

21.4.1.11 MonthFromTime ( tv )

The abstract operation MonthFromTime takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 11𝔽. tvが属するmonthをidentifyするNumberを返します。month value +0𝔽はJanuaryを指定します;1𝔽はFebruaryを指定します;2𝔽はMarchを指定します;3𝔽はAprilを指定します;4𝔽はMayを指定します;5𝔽はJuneを指定します;6𝔽はJulyを指定します;7𝔽はAugustを指定します;8𝔽はSeptemberを指定します;9𝔽はOctoberを指定します;10𝔽はNovemberを指定します;そして11𝔽はDecemberを指定します。MonthFromTime(+0𝔽) = +0𝔽であり、これはThursday, 1 January 1970に対応することに注意してください。 It performs the following steps when called:

  1. inLeapYearInLeapYear(tv)とする。
  2. dayWithinYearDayWithinYear(tv)とする。
  3. dayWithinYear < 31𝔽なら、+0𝔽を返す。
  4. dayWithinYear < 59𝔽 + inLeapYearなら、1𝔽を返す。
  5. dayWithinYear < 90𝔽 + inLeapYearなら、2𝔽を返す。
  6. dayWithinYear < 120𝔽 + inLeapYearなら、3𝔽を返す。
  7. dayWithinYear < 151𝔽 + inLeapYearなら、4𝔽を返す。
  8. dayWithinYear < 181𝔽 + inLeapYearなら、5𝔽を返す。
  9. dayWithinYear < 212𝔽 + inLeapYearなら、6𝔽を返す。
  10. dayWithinYear < 243𝔽 + inLeapYearなら、7𝔽を返す。
  11. dayWithinYear < 273𝔽 + inLeapYearなら、8𝔽を返す。
  12. dayWithinYear < 304𝔽 + inLeapYearなら、9𝔽を返す。
  13. dayWithinYear < 334𝔽 + inLeapYearなら、10𝔽を返す。
  14. Assert: dayWithinYear < 365𝔽 + inLeapYearである。
  15. 11𝔽を返す。

21.4.1.12 DateFromTime ( tv )

The abstract operation DateFromTime takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from 1𝔽 to 31𝔽. tvが属するmonth内のdayを返します。 It performs the following steps when called:

  1. inLeapYearInLeapYear(tv)とする。
  2. dayWithinYearDayWithinYear(tv)とする。
  3. monthMonthFromTime(tv)とする。
  4. month+0𝔽なら、dayWithinYear + 1𝔽を返す。
  5. month1𝔽なら、dayWithinYear - 30𝔽を返す。
  6. month2𝔽なら、dayWithinYear - 58𝔽 - inLeapYearを返す。
  7. month3𝔽なら、dayWithinYear - 89𝔽 - inLeapYearを返す。
  8. month4𝔽なら、dayWithinYear - 119𝔽 - inLeapYearを返す。
  9. month5𝔽なら、dayWithinYear - 150𝔽 - inLeapYearを返す。
  10. month6𝔽なら、dayWithinYear - 180𝔽 - inLeapYearを返す。
  11. month7𝔽なら、dayWithinYear - 211𝔽 - inLeapYearを返す。
  12. month8𝔽なら、dayWithinYear - 242𝔽 - inLeapYearを返す。
  13. month9𝔽なら、dayWithinYear - 272𝔽 - inLeapYearを返す。
  14. month10𝔽なら、dayWithinYear - 303𝔽 - inLeapYearを返す。
  15. Assert: month11𝔽である。
  16. dayWithinYear - 333𝔽 - inLeapYearを返す。

21.4.1.13 WeekDay ( tv )

The abstract operation WeekDay takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 6𝔽. tvが属するweekのdayをidentifyするNumberを返します。weekday value +0𝔽はSundayを指定します;1𝔽はMondayを指定します;2𝔽はTuesdayを指定します;3𝔽はWednesdayを指定します;4𝔽はThursdayを指定します;5𝔽はFridayを指定します;そして6𝔽はSaturdayを指定します。WeekDay(+0𝔽) = 4𝔽であり、これはThursday, 1 January 1970に対応することに注意してください。 It performs the following steps when called:

  1. 𝔽((Day(tv) + 4𝔽) modulo 7)を返す。

21.4.1.14 HourFromTime ( tv )

The abstract operation HourFromTime takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 23𝔽. tvが属するdayのhourを返します。 It performs the following steps when called:

  1. 𝔽(floor((tv / msPerHour)) modulo HoursPerDay)を返す。

21.4.1.15 MinFromTime ( tv )

The abstract operation MinFromTime takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 59𝔽. tvが属するhourのminuteを返します。 It performs the following steps when called:

  1. 𝔽(floor((tv / msPerMinute)) modulo MinutesPerHour)を返す。

21.4.1.16 SecFromTime ( tv )

The abstract operation SecFromTime takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 59𝔽. tvが属するminuteのsecondを返します。 It performs the following steps when called:

  1. 𝔽(floor((tv / msPerSecond)) modulo SecondsPerMinute)を返す。

21.4.1.17 msFromTime ( tv )

The abstract operation msFromTime takes argument tv (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 999𝔽. tvが属するsecondのmillisecondを返します。 It performs the following steps when called:

  1. 𝔽((tv) modulo (msPerSecond))を返す。

21.4.1.18 GetUTCEpochNanoseconds ( year, month, day, hour, minute, second, millisecond, microsecond, nanosecond )

The abstract operation GetUTCEpochNanoseconds takes arguments year (an integer), month (an integer in the inclusive interval from 1 to 12), day (an integer in the inclusive interval from 1 to 31), hour (an integer in the inclusive interval from 0 to 23), minute (an integer in the inclusive interval from 0 to 59), second (an integer in the inclusive interval from 0 to 59), millisecond (an integer in the inclusive interval from 0 to 999), microsecond (an integer in the inclusive interval from 0 to 999), and nanosecond (an integer in the inclusive interval from 0 to 999) and returns a BigInt. 返されるvalueは、与えられたISO 8601 calendar dateおよびUTCのwall-clock timeに対応する、epochからのnanosecondsの数を表します。 It performs the following steps when called:

  1. dateMakeDay(𝔽(year), 𝔽(month - 1), 𝔽(day))とする。
  2. timeMakeTime(𝔽(hour), 𝔽(minute), 𝔽(second), 𝔽(millisecond))とする。
  3. msMakeDate(date, time)とする。
  4. Assert: msintegral Numberである。
  5. ((ms) × 106 + microsecond × 103 + nanosecond)を返す。

21.4.1.19 Time Zone Identifiers

ECMAScriptにおけるtime zonesは、time zone identifiersによって表されます。これは、0x0000から0x007Fまでのinclusive interval内のcode unitsのみで構成されるStringsです。 ECMAScript implementationによってsupportされるtime zonesは、AvailableNamedTimeZoneIdentifiersによって返されるTime Zone Identifier Records[[Identifier]] fieldによって表されるavailable named time zones、またはIsTimeZoneOffsetStringtrueを返すStringsによって表されるoffset time zonesであり得ます。

primary time zone identifierは、available named time zoneのpreferred identifierです。 non-primary time zone identifierは、primary time zone identifierではないavailable named time zoneのidentifierです。 available named time zone identifierは、primary time zone identifierまたはnon-primary time zone identifierのいずれかです。 各available named time zone identifierは、exactly one available named time zoneにassociatedされます。 各available named time zoneは、exactly one primary time zone identifierおよびzero or more non-primary time zone identifiersにassociatedされます。

ECMAScript implementationsは、identifier "UTC"を持つavailable named time zoneをsupportしなければならず、これはUTC time zoneのprimary time zone identifierでなければなりません。 さらに、implementationsは任意の数の他のavailable named time zonesをsupportしてもよいです。

ECMA-402 Internationalization API specificationで記述されるtime zonesのrequirementsに従うimplementationsは、time zone awareと呼ばれます。 Time zone aware implementationsは、IANA Time Zone DatabaseのZoneおよびLink namesに対応するavailable named time zonesのみをsupportしなければなりません。 Time zone aware implementationsでは、ECMA-402 specificationで指定されるAvailableNamedTimeZoneIdentifiersによってspecificにoverriddenされる場合を除き、primary time zone identifierはIANA Time Zone DatabaseにおけるZone nameであり、non-primary time zone identifierはLink nameです。 IANA Time Zone Database全体をsupportしないimplementationsにも、time zonesを表すidentifiersとしてIANA Time Zone Database namesを使用することがrecommendedされます。

21.4.1.20 GetNamedTimeZoneEpochNanoseconds ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond )

The implementation-defined abstract operation GetNamedTimeZoneEpochNanoseconds takes arguments timeZoneIdentifier (a String), year (an integer), month (an integer in the inclusive interval from 1 to 12), day (an integer in the inclusive interval from 1 to 31), hour (an integer in the inclusive interval from 0 to 23), minute (an integer in the inclusive interval from 0 to 59), second (an integer in the inclusive interval from 0 to 59), millisecond (an integer in the inclusive interval from 0 to 999), microsecond (an integer in the inclusive interval from 0 to 999), and nanosecond (an integer in the inclusive interval from 0 to 999) and returns a List of BigInts. 返されるList内の各valueは、timeZoneIdentifierによってidentifiedされるnamed time zone内の、与えられたISO 8601 calendar dateおよびwall-clock timeに対応する、epochからのnanosecondsの数を表します。

inputがnegative time zone transitionのために複数回発生するlocal timeを表す場合(例えばdaylight saving timeが終了するとき、またはtime zone rule changeによりtime zone offsetがdecreasedされるとき)、返されるListは複数のelementsを持ち、ascending numerical valueでsortedされます。 inputがpositive time zone transitionのためにskippedされたlocal timeを表す場合(例えばdaylight saving timeが開始するとき、またはtime zone rule changeによりtime zone offsetがincreasedされるとき)、返されるListはemptyになります。 それ以外の場合、返されるListはone elementを持ちます。

time zonesに関するlocal political rulesを含まないECMAScript implementationsで使用されるGetNamedTimeZoneEpochNanosecondsのdefault implementationは、呼び出されたとき次のstepsを実行します:

  1. Assert: timeZoneIdentifier"UTC"である。
  2. epochNanosecondsGetUTCEpochNanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond)とする。
  3. « epochNanoseconds »を返す。
Note

time zone aware implementations(およびその他すべて)には、IANA Time Zone Database https://www.iana.org/time-zones/のtime zone informationを使用することがrequired(その他すべてにはrecommended)です。

America/New_Yorkにおける2017年11月5日の1:30 AMは2回repeatedされるため、GetNamedTimeZoneEpochNanoseconds("America/New_York", 2017, 11, 5, 1, 30, 0, 0, 0, 0)はlength 2のListを返し、そのfirst elementは05:30 UTC(UTC offset -04:00の01:30 US Eastern Daylight Timeに対応)を表し、second elementは06:30 UTC(UTC offset -05:00の01:30 US Eastern Standard Timeに対応)を表します。

America/New_Yorkにおける2017年3月12日の2:30 AMは存在しないため、GetNamedTimeZoneEpochNanoseconds("America/New_York", 2017, 3, 12, 2, 30, 0, 0, 0, 0)はempty Listを返します。

21.4.1.21 GetNamedTimeZoneOffsetNanoseconds ( timeZoneIdentifier, epochNanoseconds )

The implementation-defined abstract operation GetNamedTimeZoneOffsetNanoseconds takes arguments timeZoneIdentifier (a String) and epochNanoseconds (a BigInt) and returns an integer.

返されるintegerは、timeZoneIdentifierによってidentifiedされるnamed time zoneのUTCからのoffsetを表し、epochNanosecondsに対応するepoch relativeなinstantにおける値であり、いずれもnanoseconds単位です。

time zonesに関するlocal political rulesを含まないECMAScript implementationsで使用されるGetNamedTimeZoneOffsetNanosecondsのdefault implementationは、呼び出されたとき次のstepsを実行します:

  1. Assert: timeZoneIdentifier"UTC"である。
  2. 0を返す。
Note

Time zone offset valuesはpositiveまたはnegativeであり得ます。

21.4.1.22 Time Zone Identifier Record

Time Zone Identifier Recordは、available named time zone identifierおよびそれに対応するprimary time zone identifierをdescribeするために使用されるRecordです。

Time Zone Identifier Recordsは、Table 60にlistedされたfieldsを持ちます。

Table 60: Time Zone Identifier Record Fields
Field Name Value Meaning
[[Identifier]] a String implementationによってsupportされるavailable named time zone identifier
[[PrimaryIdentifier]] a String [[Identifier]]がresolveするprimary time zone identifier
Note

[[Identifier]]primary time zone identifierである場合、[[Identifier]][[PrimaryIdentifier]]です。

21.4.1.23 AvailableNamedTimeZoneIdentifiers ( )

The implementation-defined abstract operation AvailableNamedTimeZoneIdentifiers takes no arguments and returns a List of Time Zone Identifier Records. そのresultは、このimplementation内のすべてのavailable named time zone identifiers、および各available named time zone identifierに対応するprimary time zone identifierをdescribeします。 Listは各Time Zone Identifier Record[[Identifier]] fieldに従ってorderedされます。

ECMA-402 Internationalization APIをimplementするすべてのimplementationsを含むtime zone aware implementationsは、AvailableNamedTimeZoneIdentifiers abstract operationをECMA-402 specificationで指定される通りにimplementしなければなりません。 time zone awareでないimplementationsについて、AvailableNamedTimeZoneIdentifiersは呼び出されたとき次のstepsを実行します:

  1. implementationがtime zonesに関するlocal political rulesをまったく含まないなら、
    1. « the Time Zone Identifier Record { [[Identifier]]: "UTC", [[PrimaryIdentifier]]: "UTC" } »を返す。
  2. identifiersを、lexicographic code unit orderに従ってsortedされた、unique available named time zone identifiersListとする。
  3. resultを新しい空のListとする。
  4. identifiersの各要素identifierについて、以下を行う
    1. primaryidentifierとする。
    2. identifierがこのimplementation内のnon-primary time zone identifierであり、かつidentifier"UTC"でないなら、
      1. primaryidentifierにassociatedされたprimary time zone identifierに設定する。
      2. NOTE: implementationはprimary time zone identifierをobtainするためにidentifierをiterativelyにresolveする必要がある場合がある。
    3. recordTime Zone Identifier Record { [[Identifier]]: identifier, [[PrimaryIdentifier]]: primary }とする。
    4. recordresultへappendする。
  5. Assert: resultは、record.[[Identifier]]"UTC"であり、record.[[PrimaryIdentifier]]"UTC"であるようなTime Zone Identifier Record recordを含む。
  6. resultを返す。

21.4.1.24 SystemTimeZoneIdentifier ( )

The implementation-defined abstract operation SystemTimeZoneIdentifier takes no arguments and returns a String. host environmentのcurrent time zoneを表すStringを返します。これは、IsTimeZoneOffsetStringtrueを返すUTC offsetを表すString、またはprimary time zone identifierのいずれかです。 It performs the following steps when called:

  1. implementationがUTC time zoneのみをsupportするなら、"UTC"を返す。
  2. systemTimeZoneStringを、host environmentのcurrent time zoneを表すString、すなわちprimary time zone identifierまたはoffset time zone identifierとする。
  3. systemTimeZoneStringを返す。
Note

implementationsがDate objectのmethodsにおいてcommonlyに提供するlevel of functionalityをensureするため、SystemTimeZoneIdentifierは、そのようなものが存在する場合、host environmentのtime zone settingに対応するIANA time zone nameを返すことがrecommendedされます。 GetNamedTimeZoneEpochNanosecondsおよびGetNamedTimeZoneOffsetNanosecondsは、そのようなrulesが存在する場合、そのtime zoneにおけるstandard timeおよびdaylight saving timeに関するlocal political rulesをreflectしなければなりません。

例えば、host environmentが、userがtime zoneとしてUS Eastern Timeを選択したsystem上のbrowserである場合、SystemTimeZoneIdentifierは"America/New_York"を返します。

21.4.1.25 LocalTime ( tv )

The abstract operation LocalTime takes argument tv (a finite time value) and returns an integral Number. tvをUTCからlocal timeへconvertします。 tvにおいて有効なstandard timeおよびdaylight saving timeに関するlocal political rulesは、このsectionで指定される方法でresultをdetermineするために使用されるべきです。 It performs the following steps when called:

  1. systemTimeZoneIdentifierSystemTimeZoneIdentifier()とする。
  2. IsTimeZoneOffsetString(systemTimeZoneIdentifier)がtrueなら、
    1. offsetNsParseTimeZoneOffsetString(systemTimeZoneIdentifier)とする。
  3. そうでなければ、
    1. offsetNsGetNamedTimeZoneOffsetNanoseconds(systemTimeZoneIdentifier, ((tv) × 106))とする。
  4. offsetMstruncate(offsetNs / 106)とする。
  5. tv + 𝔽(offsetMs)を返す。
Note 1

local time tvに関するpolitical rulesがimplementation内でavailableでない場合、resultはtvです。なぜならSystemTimeZoneIdentifier"UTC"を返し、GetNamedTimeZoneOffsetNanosecondsは0を返すためです。

Note 2

time zone aware implementations(およびその他すべて)には、IANA Time Zone Database https://www.iana.org/time-zones/のtime zone informationを使用することがrequired(その他すべてにはrecommended)です。

Note 3

異なる2つのinput time values tvUTCは、repeated timesが存在するnegative time zone transition(例えばdaylight saving timeが終了するとき、またはtime zone adjustmentがdecreasedされるとき)に、同じlocal time tlocalへconvertedされます。

LocalTime(UTC(tvlocal))は、必ずしも常にtvlocalにequalであるとは限りません。対応して、UTC(LocalTime(tvUTC))も、必ずしも常にtvUTCにequalであるとは限りません。

21.4.1.26 UTC ( t )

The abstract operation UTC takes argument t (a Number) and returns a time value. tをlocal timeからUTC time valueへconvertします。 tにおいて有効なstandard timeおよびdaylight saving timeに関するlocal political rulesは、このsectionで指定される方法でresultをdetermineするために使用されるべきです。 It performs the following steps when called:

  1. tfiniteでないなら、NaNを返す。
  2. systemTimeZoneIdentifierSystemTimeZoneIdentifier()とする。
  3. IsTimeZoneOffsetString(systemTimeZoneIdentifier)がtrueなら、
    1. offsetNsParseTimeZoneOffsetString(systemTimeZoneIdentifier)とする。
  4. そうでなければ、
    1. possibleInstantsGetNamedTimeZoneEpochNanoseconds(systemTimeZoneIdentifier, (YearFromTime(t)), (MonthFromTime(t)) + 1, (DateFromTime(t)), (HourFromTime(t)), (MinFromTime(t)), (SecFromTime(t)), (msFromTime(t)), 0, 0)とする。
    2. NOTE: 以下のstepsは、tがnegative time zone transition(例えばdaylight saving timeが終了するとき、またはtime zone rule changeによりtime zone offsetがdecreasedされるとき)で複数回repeatingするlocal time、またはpositive time zone transition(例えばdaylight saving timeが開始するとき、またはtime zone rule changeによりtime zone offsetがincreasedされるとき)でskippedされるlocal timeを表す場合、tがtransition前のtime zone offsetを使用してinterpretedされることをensureする。
    3. possibleInstantsがemptyでないなら、
      1. disambiguatedInstantpossibleInstants[0]とする。
    4. そうでなければ、
      1. NOTE: tはpositive time zone transitionでskippedされたlocal timeを表す(例えばdaylight saving timeの開始、またはUTC offsetをincreaseするtime zone rule changeによる)。
      2. possibleInstantsBeforeGetNamedTimeZoneEpochNanoseconds(systemTimeZoneIdentifier, (YearFromTime(tBefore)), (MonthFromTime(tBefore)) + 1, (DateFromTime(tBefore)), (HourFromTime(tBefore)), (MinFromTime(tBefore)), (SecFromTime(tBefore)), (msFromTime(tBefore)), 0, 0)とする。ここで、tBeforepossibleInstantsBeforeがemptyでないようなt未満のlargest integral Numberである(すなわち、tBeforeはtransition前のlast local timeを表す)。
      3. disambiguatedInstantpossibleInstantsBeforeのlast elementとする。
    5. offsetNsGetNamedTimeZoneOffsetNanoseconds(systemTimeZoneIdentifier, disambiguatedInstant)とする。
  5. offsetMstruncate(offsetNs / 106)とする。
  6. t - 𝔽(offsetMs)を返す。

Input tはnominallyにはtime valueですが、任意のNumber valueであり得ます。 algorithmはttime value rangeにlimitしてはなりません。これにより、time value rangeのboundaryに対応するinputsが、local UTC offsetにかかわらずsupportされます。 例えば、maximum time valueは8.64 × 1015であり、"+275760-09-13T00:00:00Z"に対応します。 local time zone offsetがそのinstantでUTCより1 hour進んでいるenvironmentでは、これはより大きいinputである8.64 × 1015 + 3.6 × 106、すなわち"+275760-09-13T01:00:00+01:00"に対応するものとして表されます。

local time tに関するpolitical rulesがimplementation内でavailableでない場合、resultはtです。なぜならSystemTimeZoneIdentifier"UTC"を返し、GetNamedTimeZoneOffsetNanosecondsは0を返すためです。

Note 1

time zone aware implementations(およびその他すべて)には、IANA Time Zone Database https://www.iana.org/time-zones/のtime zone informationを使用することがrequired(その他すべてにはrecommended)です。

America/New_Yorkにおける2017年11月5日の1:30 AMは2回repeatedされます(fall backward)が、1:30 AM UTC-05ではなく1:30 AM UTC-04としてinterpretedされなければなりません。 UTC(TimeClip(MakeDate(MakeDay(2017, 10, 5), MakeTime(1, 30, 0, 0))))において、offsetMsのvalueは-4 × msPerHourです。

America/New_Yorkにおける2017年3月12日の2:30 AMは存在しませんが、2:30 AM UTC-05(3:30 AM UTC-04にequivalent)としてinterpretedされなければなりません。 UTC(TimeClip(MakeDate(MakeDay(2017, 2, 12), MakeTime(2, 30, 0, 0))))において、offsetMsのvalueは-5 × msPerHourです。

Note 2

UTC(LocalTime(tUTC))は、必ずしも常にtUTCにequalであるとは限りません。対応して、LocalTime(UTC(tlocal))も、必ずしも常にtlocalにequalであるとは限りません。

21.4.1.27 MakeTime ( hour, min, sec, ms )

The abstract operation MakeTime takes arguments hour (a Number), min (a Number), sec (a Number), and ms (a Number) and returns a Number. millisecondsの数をcalculateします。 It performs the following steps when called:

  1. hourfiniteでない、minfiniteでない、secfiniteでない、またはmsfiniteでないなら、NaNを返す。
  2. h𝔽(! ToIntegerOrInfinity(hour))とする。
  3. m𝔽(! ToIntegerOrInfinity(min))とする。
  4. s𝔽(! ToIntegerOrInfinity(sec))とする。
  5. milli𝔽(! ToIntegerOrInfinity(ms))とする。
  6. ((h × msPerHour + m × msPerMinute) + s × msPerSecond) + milliを返す。
Note

MakeTime内のarithmeticはfloating-point arithmeticであり、associativeではないため、operationsはcorrect orderでperformされなければなりません。

21.4.1.28 MakeDay ( year, month, date )

The abstract operation MakeDay takes arguments year (a Number), month (a Number), and date (a Number) and returns a finite Number or NaN. daysの数をcalculateします。 It performs the following steps when called:

  1. yearfiniteでない、monthfiniteでない、またはdatefiniteでないなら、NaNを返す。
  2. y𝔽(! ToIntegerOrInfinity(year))とする。
  3. m𝔽(! ToIntegerOrInfinity(month))とする。
  4. dt𝔽(! ToIntegerOrInfinity(date))とする。
  5. ymy + 𝔽(floor((m) / 12))とする。
  6. ymfiniteでないなら、NaNを返す。
  7. mn𝔽((m) modulo 12)とする。
  8. YearFromTime(tv)がymであり、MonthFromTime(tv)がmnであり、DateFromTime(tv)が1𝔽であるようなfinite time value tvを見つける;ただし、これが可能でない場合(あるargumentがout of rangeであるため)、NaNを返す。
  9. Day(tv) + dt - 1𝔽を返す。

21.4.1.29 MakeDate ( day, time )

The abstract operation MakeDate takes arguments day (a Number) and time (a Number) and returns a finite Number or NaN. millisecondsの数をcalculateします。 It performs the following steps when called:

  1. dayfiniteでない、またはtimefiniteでないなら、NaNを返す。
  2. tvday × msPerDay + timeとする。
  3. tvfiniteでないなら、NaNを返す。
  4. tvを返す。

21.4.1.30 MakeFullYear ( year )

The abstract operation MakeFullYear takes argument year (a Number) and returns an integral Number or NaN. yearinteger partにassociatedされたfull yearを返します。0から99までのinclusive interval内の任意のvalueは、1900年のstartからのyearsのcountとしてinterpretingされます。proleptic Gregorian calendarとのalignmentのため、“full year”はyear 0(1 B.C.)のstartからのcomplete yearsのsigned countとして定義されます。 It performs the following steps when called:

  1. yearNaN+∞𝔽、または-∞𝔽のいずれかなら、NaNを返す。
  2. truncatedを ! ToIntegerOrInfinity(year) とする。
  3. truncatedが0から99までのinclusive interval内にあるなら、1900𝔽 + 𝔽(truncated)を返す。
  4. 𝔽(truncated)を返す。

21.4.1.31 TimeClip ( time )

The abstract operation TimeClip takes argument time (a Number) and returns a time value. millisecondsの数をcalculateします。 It performs the following steps when called:

  1. timefiniteでないなら、NaNを返す。
  2. abs((time)) > 8.64 × 1015なら、NaNを返す。
  3. 𝔽(! ToIntegerOrInfinity(time))を返す。

21.4.1.32 Date Time String Format

ECMAScriptは、ISO 8601 calendar date extended formatのsimplificationに基づくdate-timesのstring interchange formatを定義します。formatは次の通りです:YYYY-MM-DDTHH:mm:ss.sssZ

elementsは次の通りです:

YYYY proleptic Gregorian calendarにおけるyearであり、0000から9999までのfour decimal digits、または"+"または"-"の後にsix decimal digitsが続くexpanded yearです。
- "-"(hyphen)はstring内にliteralに2回appearsします。
MM yearのmonthであり、01(January)から12(December)までのtwo decimal digitsです。
DD monthのdayであり、01から31までのtwo decimal digitsです。
T time elementのbeginningを示すため、"T"がstring内にliteralにappearsします。
HH midnightから経過したcomplete hoursの数であり、00から24までのtwo decimal digitsです。
: ":"(colon)はstring内にliteralに2回appearsします。
mm hourのstartからのcomplete minutesの数であり、00から59までのtwo decimal digitsです。
ss minuteのstartからのcomplete secondsの数であり、00から59までのtwo decimal digitsです。
. "."(dot)はstring内にliteralにappearsします。
sss secondのstartからのcomplete millisecondsの数であり、three decimal digitsです。
Z UTC offset representationであり、"Z"(offsetなしのUTC)として、または"+"または"-"の後にtime expression HH:mmが続くものとしてspecifiedされます(UTCよりaheadまたはbehindであるlocal timeをそれぞれ示すためのtime zone offset string formatのsubset)

このformatはdate-only formsを含みます:

YYYY
YYYY-MM
YYYY-MM-DD
        

また、上記のdate-only formsのいずれかの直後に、optional UTC offset representationがappendedされた以下のtime formsのいずれかが続く“date-time” formsも含みます:

THH:mm
THH:mm:ss
THH:mm:ss.sss
        

out-of-boundsまたはnonconforming elementsを含むstringは、このformatのvalid instanceではありません。

Note 1

すべての日はmidnightでstartしmidnightでendするため、notation 00:00および24:00の2つは、one dateにassociatedされ得る2つのmidnightsをdistinguishするためにavailableです。これは、次の2つのnotationsがexactly same point in timeをreferすることを意味します:1995-02-04T24:00および1995-02-05T00:00。後者のformを“calendar dayのend”としてinterpretすることは、そのspecificationがtime intervalsをdescribingするためにreservedし、single points in timeのrepresentations内ではpermitしていないとしても、ISO 8601とconsistentです。

Note 2

CET、ESTなどのcivil time zonesのabbreviationsをspecifyするinternational standardは存在せず、ときには同じabbreviationが非常に異なる2つのtime zonesに使用されることすらあります。この理由により、ISO 8601とこのformatの両方は、time zone offsetsのnumeric representationsを指定します。

21.4.1.32.1 Expanded Years

1970年1月1日からforwardまたはbackwardにおよそ273,790年というfull time value range(21.4.1.1)をcoverするには、0より前または9999より後のyearsをrepresentする必要があります。ISO 8601はyear representationのexpansionをpermitしますが、information interchangeのpartners間のmutual agreementによる場合に限ります。simplified ECMAScript formatでは、そのようなexpanded year representationは6 digitsを持ち、常に+または- signでprefixedされなければなりません。year 0はpositiveとみなされ、+ signでprefixedされなければなりません。year 0を-000000として表すrepresentationはinvalidです。time valueのrange外のinstants in timeを表すexpanded yearsを持つDate Time String FormatにmatchingするStringsは、Date.parseによってunrecognizableとして扱われ、そのfunctionはimplementation-specific behaviourまたはheuristicsにfall backせずにNaNを返します。

Note

expanded yearsを持つdate-time valuesのexamples:

-271821-04-20T00:00:00Z 271822 B.C.
-000001-01-01T00:00:00Z 2 B.C.
+000000-01-01T00:00:00Z 1 B.C.
+000001-01-01T00:00:00Z 1 A.D.
+001970-01-01T00:00:00Z 1970 A.D.
+002009-12-15T00:00:00Z 2009 A.D.
+275760-09-13T00:00:00Z 275760 A.D.

21.4.1.33 Time Zone Offset String Format

ECMAScriptは、ISO 8601からderivedされたUTC offsetsのstring interchange formatを定義します。 formatは以下のgrammarによってdescribedされます。

Syntax

UTCOffset ::: ASCIISign Hour ASCIISign Hour HourSubcomponents[+Extended] ASCIISign Hour HourSubcomponents[~Extended] ASCIISign ::: one of + - Hour ::: 0 DecimalDigit 1 DecimalDigit 20 21 22 23 HourSubcomponents[Extended] ::: TimeSeparator[?Extended] MinuteSecond TimeSeparator[?Extended] MinuteSecond TimeSeparator[?Extended] MinuteSecond TemporalDecimalFractionopt TimeSeparator[Extended] ::: [+Extended] : [~Extended] [empty] MinuteSecond ::: 0 DecimalDigit 1 DecimalDigit 2 DecimalDigit 3 DecimalDigit 4 DecimalDigit 5 DecimalDigit TemporalDecimalFraction ::: TemporalDecimalSeparator DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit TemporalDecimalSeparator ::: one of . ,

21.4.1.33.1 IsTimeZoneOffsetString ( offsetString )

The abstract operation IsTimeZoneOffsetString takes argument offsetString (a String) and returns a Boolean. return valueは、offsetStringUTCOffsetによって与えられるgrammarにconformするかどうかを示します。 It performs the following steps when called:

  1. parseResultParseText(offsetString, UTCOffset)とする。
  2. parseResultがerrorsのListなら、falseを返す。
  3. trueを返す。

21.4.1.33.2 ParseTimeZoneOffsetString ( offsetString )

The abstract operation ParseTimeZoneOffsetString takes argument offsetString (a String) and returns an integer. return valueは、String offsetStringに対応するUTC offsetであり、nanosecondsの数です。 It performs the following steps when called:

  1. parseResultParseText(offsetString, UTCOffset)とする。
  2. Assert: parseResultはerrorsのListではない。
  3. Assert: parseResultASCIISign Parse Nodeを含む。
  4. parsedSignparseResult内に含まれるASCIISign Parse Nodeにmatchedするsource textとする。
  5. parsedSignがsingle code point U+002D (HYPHEN-MINUS)なら、
    1. signを-1とする。
  6. そうでなければ、
    1. signを1とする。
  7. NOTE: 以下のStringToNumberのapplicationsはprecisionを失わない。なぜなら、parsed valuesのそれぞれは十分に短いdecimal digitsのstringであることがguaranteedされるからである。
  8. Assert: parseResultHour Parse Nodeを含む。
  9. parsedHoursparseResult内に含まれるHour Parse Nodeにmatchedするsource textとする。
  10. hours(StringToNumber(CodePointsToString(parsedHours)))とする。
  11. parseResultMinuteSecond Parse Nodeを含まないなら、
    1. minutesを0とする。
  12. そうでなければ、
    1. parsedMinutesparseResult内に含まれるfirst MinuteSecond Parse Nodeにmatchedするsource textとする。
    2. minutes(StringToNumber(CodePointsToString(parsedMinutes)))とする。
  13. parseResultがtwo MinuteSecond Parse Nodesを含まないなら、
    1. secondsを0とする。
  14. そうでなければ、
    1. parsedSecondsparseResult内に含まれるsecond MinuteSecond Parse Nodeにmatchedするsource textとする。
    2. seconds(StringToNumber(CodePointsToString(parsedSeconds)))とする。
  15. parseResultTemporalDecimalFraction Parse Nodeを含まないなら、
    1. nanosecondsを0とする。
  16. そうでなければ、
    1. parsedFractionparseResult内に含まれるTemporalDecimalFraction Parse Nodeにmatchedするsource textとする。
    2. fractionCodePointsToString(parsedFraction)と"000000000"string-concatenationとする。
    3. nanosecondsStringfractionの1から10までのsubstringとする。
    4. nanoseconds(StringToNumber(nanosecondsString))とする。
  17. sign × (((hours × 60 + minutes) × 60 + seconds) × 109 + nanoseconds)を返す。

21.4.2 The Date Constructor

Date constructorは:

  • %Date%です。
  • global object"Date" propertyのinitial valueです。
  • constructorとして呼び出されたとき、新しいDateを作成およびinitializeします。
  • constructorとしてではなくfunctionとして呼び出されたとき、current time(UTC)を表すStringを返します。
  • そのbehaviourがargumentsのnumberおよびtypesに基づいて異なるfunctionです。
  • class definitionのextends clauseのvalueとして使用できます。指定されたDate behaviourをinheritしようとするsubclass constructorsは、[[DateValue]] internal slotを持つsubclass instanceを作成およびinitializeするために、Date constructorへのsuper callを含まなければなりません。

21.4.2.1 Date ( ...values )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. NewTargetがundefinedなら、
    1. nowをcurrent timeをidentifyするtime value(UTC)とする。
    2. ToDateString(now)を返す。
  2. numberOfArgsvalues内のelementsの数とする。
  3. numberOfArgs = 0なら、
    1. dvをcurrent timeをidentifyするtime value(UTC)とする。
  4. そうでなく、numberOfArgs = 1なら、
    1. valuevalues[0]とする。
    2. valueがObjectであり、value[[DateValue]] internal slotを持つなら、
      1. tvvalue.[[DateValue]]とする。
    3. そうでなければ、
      1. vを ? ToPrimitive(value) とする。
      2. vがStringなら、
        1. Assert: vはStringであるため、next stepはabrupt completionを返すことはない。
        2. tvを、parse method(21.4.3.2)の場合とexactly same mannerで、vをdateとしてparsingしたresultとする。
      3. そうでなければ、
        1. tvを ? ToNumber(v) とする。
    4. dvTimeClip(tv)とする。
  5. そうでなければ、
    1. Assert: numberOfArgs ≥ 2である。
    2. yを ? ToNumber(values[0]) とする。
    3. mを ? ToNumber(values[1]) とする。
    4. numberOfArgs > 2なら、dtを ? ToNumber(values[2]) とする;そうでなければ、dt1𝔽とする。
    5. numberOfArgs > 3なら、hを ? ToNumber(values[3]) とする;そうでなければ、h+0𝔽とする。
    6. numberOfArgs > 4なら、minを ? ToNumber(values[4]) とする;そうでなければ、min+0𝔽とする。
    7. numberOfArgs > 5なら、sを ? ToNumber(values[5]) とする;そうでなければ、s+0𝔽とする。
    8. numberOfArgs > 6なら、milliを ? ToNumber(values[6]) とする;そうでなければ、milli+0𝔽とする。
    9. yrMakeFullYear(y)とする。
    10. finalDateMakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli))とする。
    11. dvTimeClip(UTC(finalDate))とする。
  6. objを ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] ») とする。
  7. obj.[[DateValue]]dvに設定する。
  8. objを返す。

21.4.3 Properties of the Date Constructor

Date constructorは:

  • valueが%Function.prototype%である[[Prototype]] internal slotを持ちます。
  • valueが7𝔽である"length" propertyを持ちます。
  • 次のpropertiesを持ちます:

21.4.3.1 Date.now ( )

このfunctionは、それへのcallのoccurrenceのUTC dateおよびtimeをdesignateするtime valueを返します。

21.4.3.2 Date.parse ( string )

このfunctionは、そのargumentにToString operatorをapplyします。ToStringabrupt completionとなった場合、Completion Recordがimmediatelyに返されます。そうでなければ、このfunctionは得られたStringをdateおよびtimeとしてinterpretします;これは、dateおよびtimeに対応するUTC time valueであるNumberを返します。Stringのcontentsに応じて、Stringはlocal time、UTC time、またはsome other time zoneのtimeとしてinterpretedされ得ます。functionはまず、expanded yearsを含め、Date Time String Format(21.4.1.32)でdescribedされたformatに従ってStringをparseしようとします。Stringがそのformatにconformしない場合、functionは任意のimplementation-specific heuristicsまたはimplementation-specific date formatsにfall backしてもよいです。unrecognizableである、またはout-of-bounds format element valuesを含むStringsは、このfunctionにNaNを返させなければなりません。

StringがDate Time String Formatにconformする場合、absent format elementsのplaceにはsubstitute valuesが入ります。MMまたはDD elementsがabsentである場合、"01"が使用されます。HHmm、またはss elementsがabsentである場合、"00"が使用されます。sss elementがabsentである場合、"000"が使用されます。UTC offset representationがabsentである場合、date-only formsはUTC timeとしてinterpretedされ、date-time formsはlocal timeとしてinterpretedされます。

xが、ECMAScriptの特定のimplementation内でmilliseconds amountがzeroである任意のDateである場合、referencedされるすべてのpropertiesがinitial valuesを持つなら、以下のexpressionsはすべて、そのimplementation内でsame numeric valueをproduceすべきです:

x.valueOf()
Date.parse(x.toString())
Date.parse(x.toUTCString())
Date.parse(x.toISOString())

しかし、expression

Date.parse(x.toLocaleString())

は、preceding three expressionsとsame Number valueをproduceすることはrequiredではなく、generalに、このfunctionによってproduceされるvalueは、Date Time String Format(21.4.1.32)にconformせず、かつそのimplementationでtoStringまたはtoUTCString methodによってproduceされ得ない任意のString valueが与えられた場合、implementation-definedです。

21.4.3.3 Date.prototype

Date.prototypeのinitial valueはDate prototype objectです。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }を持ちます。

21.4.3.4 Date.UTC ( year [ , month [ , date [ , hours [ , minutes [ , seconds [ , ms ] ] ] ] ] ] )

このfunctionは呼び出されたとき、次のstepsを実行します:

  1. yを ? ToNumber(year) とする。
  2. monthがpresentなら、mを ? ToNumber(month) とする;そうでなければ、m+0𝔽とする。
  3. dateがpresentなら、dtを ? ToNumber(date) とする;そうでなければ、dt1𝔽とする。
  4. hoursがpresentなら、hを ? ToNumber(hours) とする;そうでなければ、h+0𝔽とする。
  5. minutesがpresentなら、minを ? ToNumber(minutes) とする;そうでなければ、min+0𝔽とする。
  6. secondsがpresentなら、sを ? ToNumber(seconds) とする;そうでなければ、s+0𝔽とする。
  7. msがpresentなら、milliを ? ToNumber(ms) とする;そうでなければ、milli+0𝔽とする。
  8. yrMakeFullYear(y)とする。
  9. TimeClip(MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)))を返す。

このfunctionの"length" propertyは7𝔽です。

Note

このfunctionはDate constructorと2つの点で異なります:これはDateを作成するのではなくNumberとしてtime valueを返し、argumentsをlocal timeとしてではなくUTCとしてinterpretします。

21.4.4 Properties of the Date Prototype Object

Date prototype objectは:

  • %Date.prototype%です。
  • それ自体がordinary objectです。
  • Date instanceではなく、[[DateValue]] internal slotを持ちません。
  • valueが%Object.prototype%である[[Prototype]] internal slotを持ちます。

明示的に別途定義されない限り、以下で定義されるDate prototype objectのmethodsはgenericではなく、それらに渡されるthis valueは、time valueへinitialized済みの[[DateValue]] internal slotを持つobjectでなければなりません。

21.4.4.1 Date.prototype.constructor

Date.prototype.constructorのinitial valueは%Date%です。

21.4.4.2 Date.prototype.getDate ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. DateFromTime(LocalTime(tv))を返す。

21.4.4.3 Date.prototype.getDay ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. WeekDay(LocalTime(tv))を返す。

21.4.4.4 Date.prototype.getFullYear ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. YearFromTime(LocalTime(tv))を返す。

21.4.4.5 Date.prototype.getHours ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. HourFromTime(LocalTime(tv))を返す。

21.4.4.6 Date.prototype.getMilliseconds ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. msFromTime(LocalTime(tv))を返す。

21.4.4.7 Date.prototype.getMinutes ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. MinFromTime(LocalTime(tv))を返す。

21.4.4.8 Date.prototype.getMonth ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. MonthFromTime(LocalTime(tv))を返す。

21.4.4.9 Date.prototype.getSeconds ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. SecFromTime(LocalTime(tv))を返す。

21.4.4.10 Date.prototype.getTime ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. dateObj.[[DateValue]]を返す。

21.4.4.11 Date.prototype.getTimezoneOffset ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. (tv - LocalTime(tv)) / msPerMinuteを返す。

21.4.4.12 Date.prototype.getUTCDate ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. DateFromTime(tv)を返す。

21.4.4.13 Date.prototype.getUTCDay ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. WeekDay(tv)を返す。

21.4.4.14 Date.prototype.getUTCFullYear ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. YearFromTime(tv)を返す。

21.4.4.15 Date.prototype.getUTCHours ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. HourFromTime(tv)を返す。

21.4.4.16 Date.prototype.getUTCMilliseconds ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. msFromTime(tv)を返す。

21.4.4.17 Date.prototype.getUTCMinutes ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. MinFromTime(tv)を返す。

21.4.4.18 Date.prototype.getUTCMonth ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. MonthFromTime(tv)を返す。

21.4.4.19 Date.prototype.getUTCSeconds ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、NaNを返す。
  5. SecFromTime(tv)を返す。

21.4.4.20 Date.prototype.setDate ( date )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. dtを ? ToNumber(date) とする。
  5. tvNaNなら、NaNを返す。
  6. tvLocalTime(tv)に設定する。
  7. newDateMakeDate(MakeDay(YearFromTime(tv), MonthFromTime(tv), dt), TimeWithinDay(tv))とする。
  8. uTimeClip(UTC(newDate))とする。
  9. dateObj.[[DateValue]]uに設定する。
  10. uを返す。

21.4.4.21 Date.prototype.setFullYear ( year [ , month [ , date ] ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. yを ? ToNumber(year) とする。
  5. tvNaNなら、tv+0𝔽に設定する;そうでなければ、tvLocalTime(tv)に設定する。
  6. monthがpresentなら、mを ? ToNumber(month) とする;そうでなければ、mMonthFromTime(tv)とする。
  7. dateがpresentなら、dtを ? ToNumber(date) とする;そうでなければ、dtDateFromTime(tv)とする。
  8. newDateMakeDate(MakeDay(y, m, dt), TimeWithinDay(tv))とする。
  9. uTimeClip(UTC(newDate))とする。
  10. dateObj.[[DateValue]]uに設定する。
  11. uを返す。

このmethodの"length" propertyは3𝔽です。

Note

monthがpresentでない場合、このmethodはmonthがvalue getMonth()でpresentであったかのようにbehaveします。dateがpresentでない場合、dateがvalue getDate()でpresentであったかのようにbehaveします。

21.4.4.22 Date.prototype.setHours ( hour [ , min [ , sec [ , ms ] ] ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. hを ? ToNumber(hour) とする。
  5. minがpresentなら、mを ? ToNumber(min) とする。
  6. secがpresentなら、sを ? ToNumber(sec) とする。
  7. msがpresentなら、milliを ? ToNumber(ms) とする。
  8. tvNaNなら、NaNを返す。
  9. tvLocalTime(tv)に設定する。
  10. minがpresentでないなら、mMinFromTime(tv)とする。
  11. secがpresentでないなら、sSecFromTime(tv)とする。
  12. msがpresentでないなら、millimsFromTime(tv)とする。
  13. dateMakeDate(Day(tv), MakeTime(h, m, s, milli))とする。
  14. uTimeClip(UTC(date))とする。
  15. dateObj.[[DateValue]]uに設定する。
  16. uを返す。

このmethodの"length" propertyは4𝔽です。

Note

minがpresentでない場合、このmethodはminがvalue getMinutes()でpresentであったかのようにbehaveします。secがpresentでない場合、secがvalue getSeconds()でpresentであったかのようにbehaveします。msがpresentでない場合、msがvalue getMilliseconds()でpresentであったかのようにbehaveします。

21.4.4.23 Date.prototype.setMilliseconds ( ms )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. msを ? ToNumber(ms) に設定する。
  5. tvNaNなら、NaNを返す。
  6. tvLocalTime(tv)に設定する。
  7. timeMakeTime(HourFromTime(tv), MinFromTime(tv), SecFromTime(tv), ms)とする。
  8. uTimeClip(UTC(MakeDate(Day(tv), time)))とする。
  9. dateObj.[[DateValue]]uに設定する。
  10. uを返す。

21.4.4.24 Date.prototype.setMinutes ( min [ , sec [ , ms ] ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. mを ? ToNumber(min) とする。
  5. secがpresentなら、sを ? ToNumber(sec) とする。
  6. msがpresentなら、milliを ? ToNumber(ms) とする。
  7. tvNaNなら、NaNを返す。
  8. tvLocalTime(tv)に設定する。
  9. secがpresentでないなら、sSecFromTime(tv)とする。
  10. msがpresentでないなら、millimsFromTime(tv)とする。
  11. dateMakeDate(Day(tv), MakeTime(HourFromTime(tv), m, s, milli))とする。
  12. uTimeClip(UTC(date))とする。
  13. dateObj.[[DateValue]]uに設定する。
  14. uを返す。

このmethodの"length" propertyは3𝔽です。

Note

secがpresentでない場合、このmethodはsecがvalue getSeconds()でpresentであったかのようにbehaveします。msがpresentでない場合、これはmsがvalue getMilliseconds()でpresentであったかのようにbehaveします。

21.4.4.25 Date.prototype.setMonth ( month [ , date ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. mを ? ToNumber(month) とする。
  5. dateがpresentなら、dtを ? ToNumber(date) とする。
  6. tvNaNなら、NaNを返す。
  7. tvLocalTime(tv)に設定する。
  8. dateがpresentでないなら、dtDateFromTime(tv)とする。
  9. newDateMakeDate(MakeDay(YearFromTime(tv), m, dt), TimeWithinDay(tv))とする。
  10. uTimeClip(UTC(newDate))とする。
  11. dateObj.[[DateValue]]uに設定する。
  12. uを返す。

このmethodの"length" propertyは2𝔽です。

Note

dateがpresentでない場合、このmethodはdateがvalue getDate()でpresentであったかのようにbehaveします。

21.4.4.26 Date.prototype.setSeconds ( sec [ , ms ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. sを ? ToNumber(sec) とする。
  5. msがpresentなら、milliを ? ToNumber(ms) とする。
  6. tvNaNなら、NaNを返す。
  7. tvLocalTime(tv)に設定する。
  8. msがpresentでないなら、millimsFromTime(tv)とする。
  9. dateMakeDate(Day(tv), MakeTime(HourFromTime(tv), MinFromTime(tv), s, milli))とする。
  10. uTimeClip(UTC(date))とする。
  11. dateObj.[[DateValue]]uに設定する。
  12. uを返す。

このmethodの"length" propertyは2𝔽です。

Note

msがpresentでない場合、このmethodはmsがvalue getMilliseconds()でpresentであったかのようにbehaveします。

21.4.4.27 Date.prototype.setTime ( time )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tを ? ToNumber(time) とする。
  4. vTimeClip(t)とする。
  5. dateObj.[[DateValue]]vに設定する。
  6. vを返す。

21.4.4.28 Date.prototype.setUTCDate ( date )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. dtを ? ToNumber(date) とする。
  5. tvNaNなら、NaNを返す。
  6. newDateMakeDate(MakeDay(YearFromTime(tv), MonthFromTime(tv), dt), TimeWithinDay(tv))とする。
  7. vTimeClip(newDate)とする。
  8. dateObj.[[DateValue]]vに設定する。
  9. vを返す。

21.4.4.29 Date.prototype.setUTCFullYear ( year [ , month [ , date ] ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、tv+0𝔽に設定する。
  5. yを ? ToNumber(year) とする。
  6. monthがpresentなら、mを ? ToNumber(month) とする;そうでなければ、mMonthFromTime(tv)とする。
  7. dateがpresentなら、dtを ? ToNumber(date) とする;そうでなければ、dtDateFromTime(tv)とする。
  8. newDateMakeDate(MakeDay(y, m, dt), TimeWithinDay(tv))とする。
  9. vTimeClip(newDate)とする。
  10. dateObj.[[DateValue]]vに設定する。
  11. vを返す。

このmethodの"length" propertyは3𝔽です。

Note

monthがpresentでない場合、このmethodはmonthがvalue getUTCMonth()でpresentであったかのようにbehaveします。dateがpresentでない場合、dateがvalue getUTCDate()でpresentであったかのようにbehaveします。

21.4.4.30 Date.prototype.setUTCHours ( hour [ , min [ , sec [ , ms ] ] ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. hを ? ToNumber(hour) とする。
  5. minがpresentなら、mを ? ToNumber(min) とする。
  6. secがpresentなら、sを ? ToNumber(sec) とする。
  7. msがpresentなら、milliを ? ToNumber(ms) とする。
  8. tvNaNなら、NaNを返す。
  9. minがpresentでないなら、mMinFromTime(tv)とする。
  10. secがpresentでないなら、sSecFromTime(tv)とする。
  11. msがpresentでないなら、millimsFromTime(tv)とする。
  12. dateMakeDate(Day(tv), MakeTime(h, m, s, milli))とする。
  13. vTimeClip(date)とする。
  14. dateObj.[[DateValue]]vに設定する。
  15. vを返す。

このmethodの"length" propertyは4𝔽です。

Note

minがpresentでない場合、このmethodはminがvalue getUTCMinutes()でpresentであったかのようにbehaveします。secがpresentでない場合、secがvalue getUTCSeconds()でpresentであったかのようにbehaveします。msがpresentでない場合、msがvalue getUTCMilliseconds()でpresentであったかのようにbehaveします。

21.4.4.31 Date.prototype.setUTCMilliseconds ( ms )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. msを ? ToNumber(ms) に設定する。
  5. tvNaNなら、NaNを返す。
  6. timeMakeTime(HourFromTime(tv), MinFromTime(tv), SecFromTime(tv), ms)とする。
  7. vTimeClip(MakeDate(Day(tv), time))とする。
  8. dateObj.[[DateValue]]vに設定する。
  9. vを返す。

21.4.4.32 Date.prototype.setUTCMinutes ( min [ , sec [ , ms ] ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. mを ? ToNumber(min) とする。
  5. secがpresentなら、sを ? ToNumber(sec) とする。
  6. msがpresentなら、milliを ? ToNumber(ms) とする。
  7. tvNaNなら、NaNを返す。
  8. secがpresentでないなら、sSecFromTime(tv)とする。
  9. msがpresentでないなら、millimsFromTime(tv)とする。
  10. dateMakeDate(Day(tv), MakeTime(HourFromTime(tv), m, s, milli))とする。
  11. vTimeClip(date)とする。
  12. dateObj.[[DateValue]]vに設定する。
  13. vを返す。

このmethodの"length" propertyは3𝔽です。

Note

secがpresentでない場合、このmethodはsecがvalue getUTCSeconds()でpresentであったかのようにbehaveします。msがpresentでない場合、msgetUTCMilliseconds()によって返されるvalueでpresentであったかのようにbehaveします。

21.4.4.33 Date.prototype.setUTCMonth ( month [ , date ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. mを ? ToNumber(month) とする。
  5. dateがpresentなら、dtを ? ToNumber(date) とする。
  6. tvNaNなら、NaNを返す。
  7. dateがpresentでないなら、dtDateFromTime(tv)とする。
  8. newDateMakeDate(MakeDay(YearFromTime(tv), m, dt), TimeWithinDay(tv))とする。
  9. vTimeClip(newDate)とする。
  10. dateObj.[[DateValue]]vに設定する。
  11. vを返す。

このmethodの"length" propertyは2𝔽です。

Note

dateがpresentでない場合、このmethodはdateがvalue getUTCDate()でpresentであったかのようにbehaveします。

21.4.4.34 Date.prototype.setUTCSeconds ( sec [ , ms ] )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. sを ? ToNumber(sec) とする。
  5. msがpresentなら、milliを ? ToNumber(ms) とする。
  6. tvNaNなら、NaNを返す。
  7. msがpresentでないなら、millimsFromTime(tv)とする。
  8. dateMakeDate(Day(tv), MakeTime(HourFromTime(tv), MinFromTime(tv), s, milli))とする。
  9. vTimeClip(date)とする。
  10. dateObj.[[DateValue]]vに設定する。
  11. vを返す。

このmethodの"length" propertyは2𝔽です。

Note

msがpresentでない場合、このmethodはmsがvalue getUTCMilliseconds()でpresentであったかのようにbehaveします。

21.4.4.35 Date.prototype.toDateString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、"Invalid Date"を返す。
  5. tLocalTime(tv)とする。
  6. DateString(t)を返す。

21.4.4.36 Date.prototype.toISOString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、RangeError例外をthrowする。
  5. Assert: tvintegral Numberである。
  6. tvDate Time String Formatでrepresentできないyearに対応するなら、RangeError例外をthrowする。
  7. UTC time scale上で、すべてのformat elementsおよびUTC offset representation "Z"を含む、Date Time String FormatにおけるtvのString representationを返す。

21.4.4.37 Date.prototype.toJSON ( key )

このmethodは、JSON.stringify25.5.4)による使用のためにDateのString representationを提供します。

これは呼び出されたとき、次のstepsを実行します:

  1. objを ? ToObject(this value) とする。
  2. tvを ? ToPrimitive(obj, number) とする。
  3. tvがNumberであり、かつtvfiniteでないなら、nullを返す。
  4. Invoke(obj, "toISOString")を返す。
Note 1

argumentはignoredされます。

Note 2

このmethodは意図的にgenericです;そのthis valueがDateであることをrequireしません。したがって、methodとして使用するために他の種類のobjectsへtransferできます。ただし、そのようなobjectはtoISOString methodを持つ必要があります。

21.4.4.38 Date.prototype.toLocaleDateString ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodはString valueを返します。Stringのcontentsはimplementation-definedですが、host environmentのcurrent localeのconventionsに対応するconvenientでhuman-readableなformで、current time zoneにおけるDateの“date” portionを表すことを意図しています。

このmethodのoptional parametersのmeaningはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodはString valueを返します。Stringのcontentsはimplementation-definedですが、host environmentのcurrent localeのconventionsに対応するconvenientでhuman-readableなformで、current time zoneにおけるDateを表すことを意図しています。

このmethodのoptional parametersのmeaningはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] )

ECMA-402 Internationalization APIを含むECMAScript implementationは、このmethodをECMA-402 specificationで指定される通りにimplementしなければなりません。ECMAScript implementationがECMA-402 APIを含まない場合、このmethodの次のspecificationが使用されます:

このmethodはString valueを返します。Stringのcontentsはimplementation-definedですが、host environmentのcurrent localeのconventionsに対応するconvenientでhuman-readableなformで、current time zoneにおけるDateの“time” portionを表すことを意図しています。

このmethodのoptional parametersのmeaningはECMA-402 specificationで定義されます;ECMA-402 supportを含まないimplementationsは、それらのparameter positionsを他の目的に使用してはなりません。

21.4.4.41 Date.prototype.toString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. ToDateString(tv)を返す。
Note 1

d.[[DateValue]]が1000でevenly divisibleである任意のDate dについて、Date.parse(d.toString()) = d.valueOf()のresultになります。21.4.3.2を参照してください。

Note 2

このmethodはgenericではありません;そのthis valueがDateでない場合、TypeError例外をthrowします。したがって、methodとして使用するために他の種類のobjectsへtransferすることはできません。

21.4.4.41.1 TimeString ( tv )

The abstract operation TimeString takes argument tv (a Number, but not NaN) and returns a String. It performs the following steps when called:

  1. hourToZeroPaddedDecimalString((HourFromTime(tv)), 2)とする。
  2. minuteToZeroPaddedDecimalString((MinFromTime(tv)), 2)とする。
  3. secondToZeroPaddedDecimalString((SecFromTime(tv)), 2)とする。
  4. hour":"minute":"second、code unit 0x0020 (SPACE)、および"GMT"string-concatenationを返す。

21.4.4.41.2 DateString ( tv )

The abstract operation DateString takes argument tv (a Number, but not NaN) and returns a String. It performs the following steps when called:

  1. weekdayを、WeekDay(tv)のNumberを持つTable 61内のentryのNameとする。
  2. monthを、MonthFromTime(tv)のNumberを持つTable 62内のentryのNameとする。
  3. dayToZeroPaddedDecimalString((DateFromTime(tv)), 2)とする。
  4. yvYearFromTime(tv)とする。
  5. yv+0𝔽またはyv > +0𝔽なら、yearSignをempty Stringとする;そうでなければ、yearSign"-"とする。
  6. paddedYearToZeroPaddedDecimalString(abs((yv)), 4)とする。
  7. weekday、code unit 0x0020 (SPACE)、month、code unit 0x0020 (SPACE)、day、code unit 0x0020 (SPACE)、yearSign、およびpaddedYearstring-concatenationを返す。
Table 61: Names of days of the week
Number Name
+0𝔽 "Sun"
1𝔽 "Mon"
2𝔽 "Tue"
3𝔽 "Wed"
4𝔽 "Thu"
5𝔽 "Fri"
6𝔽 "Sat"
Table 62: Names of months of the year
Number Name
+0𝔽 "Jan"
1𝔽 "Feb"
2𝔽 "Mar"
3𝔽 "Apr"
4𝔽 "May"
5𝔽 "Jun"
6𝔽 "Jul"
7𝔽 "Aug"
8𝔽 "Sep"
9𝔽 "Oct"
10𝔽 "Nov"
11𝔽 "Dec"

21.4.4.41.3 TimeZoneString ( tv )

The abstract operation TimeZoneString takes argument tv (an integral Number) and returns a String. It performs the following steps when called:

  1. systemTimeZoneIdentifierSystemTimeZoneIdentifier()とする。
  2. IsTimeZoneOffsetString(systemTimeZoneIdentifier)がtrueなら、
    1. offsetNsParseTimeZoneOffsetString(systemTimeZoneIdentifier)とする。
  3. そうでなければ、
    1. offsetNsGetNamedTimeZoneOffsetNanoseconds(systemTimeZoneIdentifier, ((tv) × 106))とする。
  4. offset𝔽(truncate(offsetNs / 106))とする。
  5. offset+0𝔽またはoffset > +0𝔽なら、
    1. offsetSign"+"とする。
    2. absOffsetoffsetとする。
  6. そうでなければ、
    1. offsetSign"-"とする。
    2. absOffsetを-offsetとする。
  7. offsetMinToZeroPaddedDecimalString((MinFromTime(absOffset)), 2)とする。
  8. offsetHourToZeroPaddedDecimalString((HourFromTime(absOffset)), 2)とする。
  9. tzNameを、empty String、またはcode unit 0x0020 (SPACE)、code unit 0x0028 (LEFT PARENTHESIS)、implementation-defined timezone name、およびcode unit 0x0029 (RIGHT PARENTHESIS)のstring-concatenationのいずれかであるimplementation-defined stringとする。
  10. offsetSignoffsetHouroffsetMin、およびtzNamestring-concatenationを返す。

21.4.4.41.4 ToDateString ( tv )

The abstract operation ToDateString takes argument tv (an integral Number or NaN) and returns a String. It performs the following steps when called:

  1. tvNaNなら、"Invalid Date"を返す。
  2. localTimeLocalTime(tv)とする。
  3. DateString(localTime)、code unit 0x0020 (SPACE)、TimeString(localTime)、およびTimeZoneString(tv)のstring-concatenationを返す。

21.4.4.42 Date.prototype.toTimeString ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、"Invalid Date"を返す。
  5. localTimeLocalTime(tv)とする。
  6. TimeString(localTime)とTimeZoneString(tv)のstring-concatenationを返す。

21.4.4.43 Date.prototype.toUTCString ( )

このmethodは、this valueに対応するinstant in timeを表すString valueを返します。StringのformatはRFC 7231のHTTP-dateに基づき、ECMAScript Datesによってsupportされるfull range of timesをsupportするようgeneralizedされています。

これは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. tvdateObj.[[DateValue]]とする。
  4. tvNaNなら、"Invalid Date"を返す。
  5. weekdayを、WeekDay(tv)のNumberを持つTable 61内のentryのNameとする。
  6. monthを、MonthFromTime(tv)のNumberを持つTable 62内のentryのNameとする。
  7. dayToZeroPaddedDecimalString((DateFromTime(tv)), 2)とする。
  8. yvYearFromTime(tv)とする。
  9. yv+0𝔽またはyv > +0𝔽なら、yearSignをempty Stringとする;そうでなければ、yearSign"-"とする。
  10. paddedYearToZeroPaddedDecimalString(abs((yv)), 4)とする。
  11. weekday","、code unit 0x0020 (SPACE)、day、code unit 0x0020 (SPACE)、month、code unit 0x0020 (SPACE)、yearSignpaddedYear、code unit 0x0020 (SPACE)、およびTimeString(tv)のstring-concatenationを返す。

21.4.4.44 Date.prototype.valueOf ( )

このmethodは呼び出されたとき、次のstepsを実行します:

  1. dateObjthis valueとする。
  2. RequireInternalSlot(dateObj, [[DateValue]])を実行する。
  3. dateObj.[[DateValue]]を返す。

21.4.4.45 Date.prototype [ %Symbol.toPrimitive% ] ( hint )

このmethodは、Dateをprimitive valueへconvertするためにECMAScript language operatorsによって呼び出されます。hintにallowedなvaluesは"default""number"、および"string"です。Datesは、"default""string"とequivalentとして扱うという点でbuilt-in ECMAScript objectの中でuniqueです。他のすべてのbuilt-in ECMAScript objectsは"default""number"とequivalentとして扱います。

これは呼び出されたとき、次のstepsを実行します:

  1. objthis valueとする。
  2. objがObjectでないなら、TypeError例外をthrowする。
  3. hint"string"または"default"のいずれかなら、
    1. tryFirststringとする。
  4. そうでなく、hint"number"なら、
    1. tryFirstnumberとする。
  5. そうでなければ、
    1. TypeError例外をThrowする。
  6. OrdinaryToPrimitive(obj, tryFirst)を返す。

このpropertyはattributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }を持ちます。

このmethodの"name" propertyのvalueは"[Symbol.toPrimitive]"です。

21.4.5 Properties of Date Instances

Date instancesは、Date prototype objectからpropertiesをinheritするordinary objectsです。Date instancesはまた[[DateValue]] internal slotを持ちます。[[DateValue]] internal slotは、このDateによって表されるtime valueです。