21 숫자와 날짜

21.1 Number 객체

21.1.1 Number 생성자

Number 생성자는:

  • is %Number%.
  • 전역 객체"Number" 속성의 초기값이다.
  • 생성자로 호출될 때 새로운 Number 객체를 생성하고 초기화한다.
  • 생성자가 아닌 함수로 호출될 때 타입 변환을 수행한다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Number 동작을 상속하려는 서브클래스 생성자는 서브클래스 인스턴스를 [[NumberData]] 내부 슬롯으로 생성하고 초기화하기 위해 Number 생성자에 대한 super 호출을 포함해야 한다.

21.1.1.1 Number ( value )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. If value is present, then
    1. Let prim be ? ToNumeric(value).
    2. If prim is a BigInt, let n be 𝔽((prim)).
    3. Else, let n be prim.
  2. Else,
    1. Let n be +0𝔽.
  3. If NewTarget is undefined, return n.
  4. Let obj be ? OrdinaryCreateFromConstructor(NewTarget, "%Number.prototype%", « [[NumberData]] »).
  5. Set obj.[[NumberData]] to n.
  6. Return obj.

21.1.2 Number 생성자의 속성

Number 생성자는:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 다음 속성을 가진다:

21.1.2.1 Number.EPSILON

Number.EPSILON의 값은 1과 1보다 큰 Number 값 중 표현 가능한 가장 작은 값과 1 사이의 차이의 크기에 대한 Number 값이며, 대략 2.2204460492503130808472633361816 × 10-16이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.2 Number.isFinite ( number )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. If number is not a Number, return false.
  2. If number is not finite, return false.
  3. Return true.

21.1.2.3 Number.isInteger ( number )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. If number is an integral Number, return true.
  2. Return false.

21.1.2.4 Number.isNaN ( number )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. If number is not a Number, return false.
  2. If number is NaN, return true.
  3. Return false.
Note

이 함수는 전역 isNaN 함수 (19.2.3)와 다른데, 인수를 Number로 변환한 뒤에 NaN인지 판단하지 않는다는 점에서 다르다.

21.1.2.5 Number.isSafeInteger ( number )

Note

정수 n은 오직 그때에만 "안전 정수"이다: Number 값으로서의 n이 어떠한 다른 정수의 Number 값과도 같지 않을 때.

이 함수는 호출될 때 다음 단계를 수행한다:

  1. If number is an integral Number, then
    1. If abs((number)) ≤ 253 - 1, return true.
  2. Return false.

21.1.2.6 Number.MAX_SAFE_INTEGER

Note

IEEE 754-2019의 정밀도 제한 때문에 반올림 동작이 필요하여, Number.MAX_SAFE_INTEGER보다 큰 모든 정수의 Number 값은 최소한 하나 이상의 다른 정수와 값을 공유한다. 따라서 그러한 큰 크기의 정수들은 안전하지 않음으로 간주되며, Number 값으로 정확히 표현되거나 서로 구별될 것이라고 보장되지 않는다. 예를 들어, 90071992547409929007199254740993는 모두 Number 값 9007199254740992𝔽로 평가된다.

Number.MAX_SAFE_INTEGER의 값은 9007199254740991𝔽 (𝔽(253 - 1))이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.7 Number.MAX_VALUE

Number.MAX_VALUE의 값은 Number 타입의 가장 큰 양의 유한 값이며, 대략 1.7976931348623157 × 10308이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.8 Number.MIN_SAFE_INTEGER

Note

IEEE 754-2019의 정밀도 제한 때문에 반올림 동작이 필요하여, Number.MIN_SAFE_INTEGER보다 작은 모든 정수의 Number 값은 최소한 하나 이상의 다른 정수와 값을 공유한다. 따라서 그러한 큰 크기의 정수들은 안전하지 않음으로 간주되며, Number 값으로 정확히 표현되거나 서로 구별될 것이라고 보장되지 않는다. 예를 들어, -9007199254740992-9007199254740993는 모두 Number 값 -9007199254740992𝔽로 평가된다.

Number.MIN_SAFE_INTEGER의 값은 -9007199254740991𝔽 (𝔽(-(253 - 1)))이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.9 Number.MIN_VALUE

Number.MIN_VALUE의 값은 Number 타입의 가장 작은 양수 값이며, 대략 5 × 10-324이다.

IEEE 754-2019 배정밀도 이진 표현에서 가능한 가장 작은 값은 비정규화(denormalized) 수이다. 만약 구현체가 비정규화 값을 지원하지 않으면, Number.MIN_VALUE의 값은 구현체가 실제로 표현할 수 있는 가장 작은 0이 아닌 양수 값이어야 한다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.10 Number.NaN

Number.NaN의 값은 NaN이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.11 Number.NEGATIVE_INFINITY

Number.NEGATIVE_INFINITY의 값은 -∞𝔽이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.12 Number.parseFloat ( string )

"parseFloat" 속성의 초기값은 %parseFloat%이다.

21.1.2.13 Number.parseInt ( string, radix )

"parseInt" 속성의 초기값은 %parseInt%이다.

21.1.2.14 Number.POSITIVE_INFINITY

Number.POSITIVE_INFINITY의 값은 +∞𝔽이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.2.15 Number.prototype

Number.prototype의 초기값은 Number 프로토타입 객체이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.1.3 Number 프로토타입 객체의 속성

Number 프로토타입 객체:

  • is %Number.prototype%.
  • 일반 객체(ordinary object)이다.
  • 자신이 Number 객체이며; [[NumberData]] 내부 슬롯의 값은 +0𝔽이다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.

달리 명시되지 않는 한, 아래에 정의된 Number 프로토타입 객체의 메서드들은 일반적(generic)이 아니며, 이들에 전달된 this 값은 Number 값이거나 Number 값으로 초기화된 [[NumberData]] 내부 슬롯을 가진 객체여야 한다.

메서드 명세에서 “this Number value”라는 구문은 메서드 호출의 this 값을 인수로 하여 추상 연산 ThisNumberValue를 호출한 결과를 가리킨다.

21.1.3.1 Number.prototype.constructor

Number.prototype.constructor의 초기값은 %Number%이다.

21.1.3.2 Number.prototype.toExponential ( fractionDigits )

이 메서드는 유효 숫자 부분의 소수점 앞에 한 자리 그리고 유효숫자 소수점 뒤에 fractionDigits 자리를 갖는 10진 지수 표기법으로 표현된 이 Number 값을 포함하는 문자열을 반환한다. 만약 fractionDigitsundefined이면, 필요한 만큼의 유효숫자 자릿수를 포함하여 Number를 고유하게 지정한다(이는 ToString과 유사하되, 이 경우 항상 지수 표기법으로 출력된다는 점이 다르다).

호출될 때 다음 단계를 수행한다:

  1. Let numberValue be ? ThisNumberValue(this value).
  2. Let fractionCount be ? ToIntegerOrInfinity(fractionDigits).
  3. Assert: If fractionDigits is undefined, then fractionCount is 0.
  4. If numberValue is not finite, return Number::toString(numberValue, 10).
  5. If fractionCount < 0 or fractionCount > 100, throw a RangeError exception.
  6. Set numberValue to (numberValue).
  7. Let sign be the empty String.
  8. If numberValue < 0, then
    1. Set sign to "-".
    2. Set numberValue to -numberValue.
  9. If numberValue = 0, then
    1. Let significand be the String value consisting of fractionCount + 1 occurrences of the code unit 0x0030 (DIGIT ZERO).
    2. Let exponent be 0.
  10. Else,
    1. If fractionDigits is not undefined, then
      1. Let exponent and intSignificand be integers such that 10fractionCountintSignificand < 10fractionCount + 1 and for which intSignificand × 10exponent - fractionCount - numberValue is as close to zero as possible. If there are two such sets of exponent and intSignificand, pick the exponent and intSignificand for which intSignificand × 10exponent - fractionCount is larger.
    2. Else,
      1. Let exponent, intSignificand, and ff be integers such that ff ≥ 0, 10ffintSignificand < 10ff + 1, 𝔽(intSignificand × 10exponent - ff) is 𝔽(numberValue), and ff is as small as possible. Note that the decimal representation of intSignificand has ff + 1 digits, intSignificand is not divisible by 10, and the least significant digit of intSignificand is not necessarily uniquely determined by these criteria.
      2. Set fractionCount to ff.
    3. Let significand be the String value consisting of the digits of the decimal representation of intSignificand (in order, with no leading zeroes).
  11. If fractionCount ≠ 0, then
    1. Let integerPart be the first code unit of significand.
    2. Let fractionalPart be the other fractionCount code units of significand.
    3. Set significand to the string-concatenation of integerPart, ".", and fractionalPart.
  12. If exponent = 0, then
    1. Let exponentSign be "+".
    2. Let exponentDigits be "0".
  13. Else,
    1. If exponent > 0, then
      1. Let exponentSign be "+".
    2. Else,
      1. Assert: exponent < 0.
      2. Let exponentSign be "-".
      3. Set exponent to -exponent.
    3. Let exponentDigits be the String value consisting of the digits of the decimal representation of exponent (in order, with no leading zeroes).
  14. Set significand to the string-concatenation of significand, "e", exponentSign, and exponentDigits.
  15. Return the string-concatenation of sign and significand.
Note

위 규칙보다 더 정확한 변환을 제공하는 구현체를 위해, 다음의 대체 버전의 단계 10.b.i를 지침으로 사용하는 것이 권장된다:

  1. Let exponent, intSignificand, and ff be integers such that ff ≥ 0, 10ffintSignificand < 10ff + 1, 𝔽(intSignificand × 10exponent - ff) is 𝔽(numberValue), and ff is as small as possible. If there are multiple possibilities for intSignificand, choose intSignificand such that 𝔽(intSignificand × 10exponent - ff) is closest to 𝔽(numberValue). If there are two such possible values of intSignificand, choose the one that is even.

21.1.3.3 Number.prototype.toFixed ( fractionDigits )

Note 1

이 메서드는 소수점 뒤에 fractionDigits 자리를 가지는 10진 고정 소수점 표기법으로 표현된 이 Number 값을 포함하는 문자열을 반환한다. 만약 fractionDigitsundefined이면 0으로 간주된다.

호출될 때 다음 단계를 수행한다:

  1. Let numberValue be ? ThisNumberValue(this value).
  2. Let fractionCount be ? ToIntegerOrInfinity(fractionDigits).
  3. Assert: If fractionDigits is undefined, then fractionCount is 0.
  4. If fractionCount is not finite, throw a RangeError exception.
  5. If fractionCount < 0 or fractionCount > 100, throw a RangeError exception.
  6. If numberValue is not finite, return Number::toString(numberValue, 10).
  7. Set numberValue to (numberValue).
  8. Let sign be the empty String.
  9. If numberValue < 0, then
    1. Set sign to "-".
    2. Set numberValue to -numberValue.
  10. If numberValue ≥ 1021, then
    1. Let digitString be ! ToString(𝔽(numberValue)).
  11. Else,
    1. Let intValue be an integer for which intValue / 10fractionCount - numberValue is as close to zero as possible. If there are two such intValue, pick the larger intValue.
    2. If intValue = 0, let digitString be "0"; else let digitString be the String value consisting of the digits of the decimal representation of intValue (in order, with no leading zeroes).
    3. If fractionCount ≠ 0, then
      1. Let digitCount be the length of digitString.
      2. If digitCountfractionCount, then
        1. Let zeroPad be the String value consisting of fractionCount + 1 - digitCount occurrences of the code unit 0x0030 (DIGIT ZERO).
        2. Set digitString to the string-concatenation of zeroPad and digitString.
        3. Set digitCount to fractionCount + 1.
      3. Let integerPart be the first digitCount - fractionCount code units of digitString.
      4. Let fractionalPart be the other fractionCount code units of digitString.
      5. Set digitString to the string-concatenation of integerPart, ".", and fractionalPart.
  12. Return the string-concatenation of sign and digitString.
Note 2

toFixed의 출력은 어떤 값들에 대해 toString보다 더 정밀할 수 있다. toString은 숫자를 인접한 Number 값들과 구별하기 위해 충분한 유효숫자만 출력하기 때문이다. 예를 들어,

(1000000000000000128).toString()"1000000000000000100"을 반환하지만
(1000000000000000128).toFixed(0)"1000000000000000128"을 반환한다.

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

ECMA-402 국제화 API를 포함하는 ECMAScript 구현체는 이 메서드를 ECMA-402 명세에 지정된 대로 구현해야 한다. 만약 구현체가 ECMA-402 API를 포함하지 않으면, 다음의 이 메서드 명세가 사용된다:

이 메서드는 호스트 환경의 현재 로케일 관습에 따라 이 Number 값을 포맷한 문자열 값을 생성한다. 이 메서드는 구현체 정의(implementation-defined)이며, toString과 같은 값을 반환해도 허용되지만 권장되지는 않는다.

이 메서드의 선택적 매개변수 의미는 ECMA-402 명세에 정의되어 있다; ECMA-402를 포함하지 않는 구현체는 해당 매개변수 위치를 다른 용도로 사용해서는 안 된다.

21.1.3.5 Number.prototype.toPrecision ( precision )

이 메서드는 이 Number 값을 다음 중 하나로 표현한 문자열을 반환한다: 유효숫자 소수점 앞에 한 자리와 유효숫자 소수점 뒤에 precision - 1 자리를 갖는 10진 지수 표기법 또는 precision 유효숫자를 갖는 10진 고정 표기법. 만약 precisionundefined이면 ToString을 대신 호출한다.

호출될 때 다음 단계를 수행한다:

  1. Let numberValue be ? ThisNumberValue(this value).
  2. If precision is undefined, return ! ToString(numberValue).
  3. Let precisionCount be ? ToIntegerOrInfinity(precision).
  4. If numberValue is not finite, return Number::toString(numberValue, 10).
  5. If precisionCount < 1 or precisionCount > 100, throw a RangeError exception.
  6. Set numberValue to (numberValue).
  7. Let sign be the empty String.
  8. If numberValue < 0, then
    1. Set sign to the code unit 0x002D (HYPHEN-MINUS).
    2. Set numberValue to -numberValue.
  9. If numberValue = 0, then
    1. Let significand be the String value consisting of precisionCount occurrences of the code unit 0x0030 (DIGIT ZERO).
    2. Let exponent be 0.
  10. Else,
    1. Let exponent and intSignificand be integers such that 10precisionCount - 1intSignificand < 10precisionCount and for which intSignificand × 10exponent - precisionCount + 1 - numberValue is as close to zero as possible. If there are two such sets of exponent and intSignificand, pick the exponent and intSignificand for which intSignificand × 10exponent - precisionCount + 1 is larger.
    2. Let significand be the String value consisting of the digits of the decimal representation of intSignificand (in order, with no leading zeroes).
    3. If exponent < -6 or exponentprecisionCount, then
      1. Assert: exponent ≠ 0.
      2. If precisionCount ≠ 1, then
        1. Let integerPart be the first code unit of significand.
        2. Let fractionalPart be the other precisionCount - 1 code units of significand.
        3. Set significand to the string-concatenation of integerPart, ".", and fractionalPart.
      3. If exponent > 0, then
        1. Let exponentSign be the code unit 0x002B (PLUS SIGN).
      4. Else,
        1. Assert: exponent < 0.
        2. Let exponentSign be the code unit 0x002D (HYPHEN-MINUS).
        3. Set exponent to -exponent.
      5. Let exponentDigits be the String value consisting of the digits of the decimal representation of exponent (in order, with no leading zeroes).
      6. Return the string-concatenation of sign, significand, the code unit 0x0065 (LATIN SMALL LETTER E), exponentSign, and exponentDigits.
  11. If exponent = precisionCount - 1, return the string-concatenation of sign and significand.
  12. If exponent ≥ 0, then
    1. Set significand to the string-concatenation of the first exponent + 1 code units of significand, the code unit 0x002E (FULL STOP), and the remaining precisionCount - (exponent + 1) code units of significand.
  13. Else,
    1. Set significand to the string-concatenation of the code unit 0x0030 (DIGIT ZERO), the code unit 0x002E (FULL STOP), -(exponent + 1) occurrences of the code unit 0x0030 (DIGIT ZERO), and the String significand.
  14. Return the string-concatenation of sign and significand.

21.1.3.6 Number.prototype.toString ( [ radix ] )

Note

선택적 radix2𝔽에서 36𝔽포함 구간에 있는 정수 Number 값이어야 한다. 만약 radixundefined이면, radix의 값으로 10𝔽가 사용된다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. Let x be ? ThisNumberValue(this value).
  2. If radix is undefined, let radixMV be 10.
  3. Else, let radixMV be ? ToIntegerOrInfinity(radix).
  4. If radixMV is not in the inclusive interval from 2 to 36, throw a RangeError exception.
  5. Return Number::toString(x, radixMV).

이 메서드는 일반적이지 않다; this 값이 Number 또는 Number 객체가 아니면 TypeError 예외를 던진다. 따라서 다른 종류의 객체로 옮겨져 메서드로 사용할 수 없다.

이 메서드의 "length" 속성은 1𝔽이다.

21.1.3.7 Number.prototype.valueOf ( )

  1. Return ? ThisNumberValue(this value).

21.1.3.7.1 ThisNumberValue ( value )

The abstract operation ThisNumberValue takes argument value (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. If value is a Number, return value.
  2. If value is an Object and value has a [[NumberData]] internal slot, then
    1. Let n be value.[[NumberData]].
    2. Assert: n is a Number.
    3. Return n.
  3. Throw a TypeError exception.

21.1.4 Number 인스턴스의 속성

Number 인스턴스는 Number 프로토타입 객체로부터 속성을 상속받는 일반 객체이다. Number 인스턴스는 또한 [[NumberData]] 내부 슬롯을 가진다. [[NumberData]] 내부 슬롯은 이 Number 객체가 나타내는 Number 값이다.

21.2 BigInt 객체

21.2.1 BigInt 생성자

BigInt 생성자는:

  • is %BigInt%.
  • 전역 객체"BigInt" 속성의 초기값이다.
  • 함수로 호출될 때 타입 변환을 수행한다 (생성자로 호출될 때는 아님).
  • new 연산자와 함께 사용되거나 서브클래싱하기 위한 용도는 아니다. 클래스 정의의 extends 절의 값으로 사용될 수 있으나, BigInt 생성자에 대한 super 호출은 예외를 발생시킬 것이다.

21.2.1.1 BigInt ( value )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. If NewTarget is not undefined, throw a TypeError exception.
  2. Let prim be ? ToPrimitive(value, number).
  3. If prim is a Number, return ? NumberToBigInt(prim).
  4. Return ? ToBigInt(prim).

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. If number is not an integral Number, throw a RangeError exception.
  2. Return ((number)).

21.2.2 BigInt 생성자의 속성

BigInt 생성자는:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 다음 속성을 가진다:

21.2.2.1 BigInt.asIntN ( bits, bigint )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Set bits to ? ToIndex(bits).
  2. Set bigint to ? ToBigInt(bigint).
  3. Let mod be (bigint) modulo 2bits.
  4. If mod ≥ 2bits - 1, return (mod - 2bits).
  5. Return (mod).

21.2.2.2 BigInt.asUintN ( bits, bigint )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Set bits to ? ToIndex(bits).
  2. Set bigint to ? ToBigInt(bigint).
  3. Return ((bigint) modulo 2bits).

21.2.2.3 BigInt.prototype

BigInt.prototype의 초기값은 BigInt 프로토타입 객체이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.2.3 BigInt 프로토타입 객체의 속성

BigInt 프로토타입 객체:

  • is %BigInt.prototype%.
  • 일반 객체이다.
  • BigInt 객체가 아니며; [[BigIntData]] 내부 슬롯을 가지지 않는다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.

메서드 명세에서 “this BigInt value”라는 구문은 메서드 호출의 this 값을 인수로 하여 추상 연산 ThisBigIntValue를 호출한 결과를 가리킨다.

21.2.3.1 BigInt.prototype.constructor

BigInt.prototype.constructor의 초기값은 %BigInt%이다.

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

ECMA-402 국제화 API를 포함하는 ECMAScript 구현체는 이 메서드를 ECMA-402 명세에 지정된 대로 구현해야 한다. 만약 구현체가 ECMA-402 API를 포함하지 않으면, 다음의 이 메서드 명세가 사용된다:

이 메서드는 호스트 환경의 현재 로케일 관습에 따라 이 BigInt 값을 포맷한 문자열 값을 생성한다. 이 메서드는 구현체 정의이며, toString과 같은 값을 반환해도 허용되지만 권장되지는 않는다.

이 메서드의 선택적 매개변수 의미는 ECMA-402 명세에 정의되어 있다; ECMA-402를 포함하지 않는 구현체는 해당 매개변수 위치를 다른 용도로 사용해서는 안 된다.

21.2.3.3 BigInt.prototype.toString ( [ radix ] )

Note

선택적 radix2𝔽에서 36𝔽포함 구간에 있는 정수 Number 값이어야 한다. 만약 radixundefined이면, radix의 값으로 10𝔽가 사용된다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. Let x be ? ThisBigIntValue(this value).
  2. If radix is undefined, let radixMV be 10.
  3. Else, let radixMV be ? ToIntegerOrInfinity(radix).
  4. If radixMV is not in the inclusive interval from 2 to 36, throw a RangeError exception.
  5. Return BigInt::toString(x, radixMV).

이 메서드는 일반적이지 않다; this 값이 BigInt 또는 BigInt 객체가 아니면 TypeError 예외를 던진다. 따라서 다른 종류의 객체로 옮겨져 메서드로 사용할 수 없다.

21.2.3.4 BigInt.prototype.valueOf ( )

  1. Return ? ThisBigIntValue(this value).

21.2.3.4.1 ThisBigIntValue ( value )

The abstract operation ThisBigIntValue takes argument value (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. If value is a BigInt, return value.
  2. If value is an Object and value has a [[BigIntData]] internal slot, then
    1. Assert: value.[[BigIntData]] is a BigInt.
    2. Return value.[[BigIntData]].
  3. Throw a TypeError exception.

21.2.3.5 BigInt.prototype [ %Symbol.toStringTag% ]

%Symbol.toStringTag% 속성의 초기값은 문자열 값 "BigInt"이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }이다.

21.2.4 BigInt 인스턴스의 속성

BigInt 인스턴스는 BigInt 프로토타입 객체로부터 속성을 상속받는 일반 객체이다. BigInt 인스턴스는 또한 [[BigIntData]] 내부 슬롯을 가진다. [[BigIntData]] 내부 슬롯은 이 BigInt 객체가 나타내는 BigInt 값이다.

21.3 Math 객체

Math 객체는:

  • is %Math%.
  • 전역 객체"Math" 속성의 초기값이다.
  • 일반 객체이다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 함수 객체가 아니다.
  • [[Construct]] 내부 메서드를 가지지 않는다; new 연산자로 생성자로 사용될 수 없다.
  • [[Call]] 내부 메서드를 가지지 않는다; 함수로 호출될 수 없다.
Note

이 명세에서, “x에 대한 Number 값”이라는 구문은 6.1.6.1에 정의된 기술적 의미를 가진다.

21.3.1 Math 객체의 값 속성

21.3.1.1 Math.E

자연로그의 밑 e에 대한 Number 값으로, 대략 2.7182818284590452354이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.3.1.2 Math.LN10

10의 자연로그에 대한 Number 값으로, 대략 2.302585092994046이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.3.1.3 Math.LN2

2의 자연로그에 대한 Number 값으로, 대략 0.6931471805599453이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.3.1.4 Math.LOG10E

자연로그의 밑 e의 상용로그(밑10)에 대한 Number 값으로, 대략 0.4342944819032518이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

Note

Math.LOG10E의 값은 Math.LN10의 값의 역수에 가깝다.

21.3.1.5 Math.LOG2E

자연로그의 밑 e의 밑2 로그에 대한 Number 값으로, 대략 1.4426950408889634이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

Note

Math.LOG2E의 값은 Math.LN2의 값의 역수에 가깝다.

21.3.1.6 Math.PI

원의 둘레와 지름의 비인 π에 대한 Number 값으로, 대략 3.1415926535897932이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.3.1.7 Math.SQRT1_2

½의 제곱근에 대한 Number 값으로, 대략 0.7071067811865476이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

Note

Math.SQRT1_2의 값은 Math.SQRT2의 값의 역수에 가깝다.

21.3.1.8 Math.SQRT2

2의 제곱근에 대한 Number 값으로, 대략 1.4142135623730951이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }이다.

21.3.1.9 Math [ %Symbol.toStringTag% ]

%Symbol.toStringTag% 속성의 초기값은 문자열 값 "Math"이다.

이 속성의 속성값은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }이다.

21.3.2 Math 객체의 함수 속성들

Note

acos, acosh, asin, asinh, atan, atanh, atan2, cbrt, cos, cosh, exp, expm1, hypot, log, log1p, log2, log10, pow, random, sin, sinh, tan, 그리고 tanh 함수들의 동작은 경계 사례에 해당하는 특정 인수 값들에 대해 특정 결과를 요구하는 것 외에는 여기서 정확히 명시되지 않는다. 다른 인수 값들에 대해서는 이러한 함수들은 익숙한 수학적 함수의 결과에 대한 근사값을 계산하도록 의도되어 있으나, 근사 알고리즘 선택에는 어느 정도의 여지가 허용된다. 일반적인 의도는 구현자가 해당 하드웨어 플랫폼에서 C 프로그래머가 사용할 수 있는 동일한 수학 라이브러리를 ECMAScript 용으로 사용할 수 있어야 한다는 것이다.

알고리즘의 선택은 구현체에 맡겨지지만, 구현체가 IEEE 754-2019 산술을 위한 근사 알고리즘으로 Sun Microsystems의 무료 배포 수학 라이브러리 fdlibm(http://www.netlib.org/fdlibm)을 사용하는 것이 권장된다(명세로는 규정되지 않음).

21.3.2.1 Math.abs ( x )

이 함수는 x의 절대값을 반환한다; 결과는 x와 동일한 크기를 가지되 양의 부호를 갖는다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is -0𝔽, return +0𝔽.
  4. If n is -∞𝔽, return +∞𝔽.
  5. If n < -0𝔽, return -n.
  6. Return n.

21.3.2.2 Math.acos ( x )

이 함수는 x의 역코사인을 반환한다. 결과는 라디안으로 표현되며 +0𝔽에서 𝔽(π)까지의 포함 구간에 있다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, n > 1𝔽, or n < -1𝔽, return NaN.
  3. If n is 1𝔽, return +0𝔽.
  4. Return an implementation-approximated Number value representing the inverse cosine of (n).

21.3.2.3 Math.acosh ( x )

이 함수는 x의 역쌍곡코사인을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +∞𝔽, return n.
  3. If n is 1𝔽, return +0𝔽.
  4. If n < 1𝔽, return NaN.
  5. Return an implementation-approximated Number value representing the inverse hyperbolic cosine of (n).

21.3.2.4 Math.asin ( x )

이 함수는 x의 역사인을 반환한다. 결과는 라디안으로 표현되며 𝔽(-π / 2)에서 𝔽(π / 2)까지의 포함 구간에 있다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n > 1𝔽 or n < -1𝔽, return NaN.
  4. Return an implementation-approximated Number value representing the inverse sine of (n).

21.3.2.5 Math.asinh ( x )

이 함수는 x의 역쌍곡사인을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0𝔽 or -0𝔽, return n.
  3. Return an implementation-approximated Number value representing the inverse hyperbolic sine of (n).

21.3.2.6 Math.atan ( x )

이 함수는 x의 역탄젠트를 반환한다. 결과는 라디안으로 표현되며 𝔽(-π / 2)에서 𝔽(π / 2)까지의 포함 구간에 있다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n is +∞𝔽, return an implementation-approximated Number value representing π / 2.
  4. If n is -∞𝔽, return an implementation-approximated Number value representing -π / 2.
  5. Return an implementation-approximated Number value representing the inverse tangent of (n).

21.3.2.7 Math.atanh ( x )

이 함수는 x의 역쌍곡탄젠트를 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n > 1𝔽 or n < -1𝔽, return NaN.
  4. If n is 1𝔽, return +∞𝔽.
  5. If n is -1𝔽, return -∞𝔽.
  6. Return an implementation-approximated Number value representing the inverse hyperbolic tangent of (n).

21.3.2.8 Math.atan2 ( y, x )

이 함수는 인수 yx의 몫 y / x의 역탄젠트를 반환한다. 결과의 사분면은 yx의 부호를 사용하여 결정된다. 두 인수를 취하는 역탄젠트 함수에서 인수 이름이 전통적으로 y가 먼저이고 x가 두번째인 것이 의도적이며 전통적이다. 결과는 -π에서 +π까지의 포함 구간으로 라디안으로 표현된다.

호출될 때 다음 단계를 수행한다:

  1. Let ny be ? ToNumber(y).
  2. Let nx be ? ToNumber(x).
  3. If ny is NaN or nx is NaN, return NaN.
  4. If ny is +∞𝔽, then
    1. If nx is +∞𝔽, return an implementation-approximated Number value representing π / 4.
    2. If nx is -∞𝔽, return an implementation-approximated Number value representing 3π / 4.
    3. Return an implementation-approximated Number value representing π / 2.
  5. If ny is -∞𝔽, then
    1. If nx is +∞𝔽, return an implementation-approximated Number value representing -π / 4.
    2. If nx is -∞𝔽, return an implementation-approximated Number value representing -3π / 4.
    3. Return an implementation-approximated Number value representing -π / 2.
  6. If ny is +0𝔽, then
    1. If nx > +0𝔽 or nx is +0𝔽, return +0𝔽.
    2. Return an implementation-approximated Number value representing π.
  7. If ny is -0𝔽, then
    1. If nx > +0𝔽 or nx is +0𝔽, return -0𝔽.
    2. Return an implementation-approximated Number value representing -π.
  8. Assert: ny is finite and is neither +0𝔽 nor -0𝔽.
  9. If ny > +0𝔽, then
    1. If nx is +∞𝔽, return +0𝔽.
    2. If nx is -∞𝔽, return an implementation-approximated Number value representing π.
    3. If nx is either +0𝔽 or -0𝔽, return an implementation-approximated Number value representing π / 2.
  10. If ny < -0𝔽, then
    1. If nx is +∞𝔽, return -0𝔽.
    2. If nx is -∞𝔽, return an implementation-approximated Number value representing -π.
    3. If nx is either +0𝔽 or -0𝔽, return an implementation-approximated Number value representing -π / 2.
  11. Assert: nx is finite and is neither +0𝔽 nor -0𝔽.
  12. Let r be the inverse tangent of abs((ny) / (nx)).
  13. If nx < -0𝔽, then
    1. If ny > +0𝔽, set r to π - r.
    2. Else, set r to -π + r.
  14. Else,
    1. If ny < -0𝔽, set r to -r.
  15. Return an implementation-approximated Number value representing r.

21.3.2.9 Math.cbrt ( x )

이 함수는 x의 세제곱근을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0𝔽 or -0𝔽, return n.
  3. Return an implementation-approximated Number value representing the cube root of (n).

21.3.2.10 Math.ceil ( x )

이 함수는 x보다 작지 않은 가장 작은(−∞에 가장 가까운) 정수 Number 값을 반환한다. 만약 x가 이미 정수 Number이면 결과는 x이다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0𝔽 or -0𝔽, return n.
  3. If n < -0𝔽 and n > -1𝔽, return -0𝔽.
  4. If n is an integral Number, return n.
  5. Return the smallest (closest to -∞) integral Number value that is not less than n.
Note

Math.ceil(x)의 값은 -Math.floor(-x)의 값과 같다.

21.3.2.11 Math.clz32 ( x )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToUint32(x).
  2. Let p be the number of leading zero bits in the unsigned 32-bit binary representation of n.
  3. Return 𝔽(p).
Note

만약 n+0𝔽 또는 -0𝔽이면, 이 메서드는 32𝔽를 반환한다. 32비트 이진 인코딩에서 최상위 비트가 1이면 이 메서드는 +0𝔽를 반환한다.

21.3.2.12 Math.cos ( x )

이 함수는 x의 코사인을 반환한다. 인수는 라디안으로 표현된다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite, return NaN.
  3. If n is either +0𝔽 or -0𝔽, return 1𝔽.
  4. Return an implementation-approximated Number value representing the cosine of (n).

21.3.2.13 Math.cosh ( x )

이 함수는 x의 쌍곡코사인을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is either +∞𝔽 or -∞𝔽, return +∞𝔽.
  4. If n is either +0𝔽 or -0𝔽, return 1𝔽.
  5. Return an implementation-approximated Number value representing the hyperbolic cosine of (n).
Note

Math.cosh(x)의 값은 (Math.exp(x) + Math.exp(-x)) / 2의 값과 같다.

21.3.2.14 Math.exp ( x )

이 함수는 x의 지수 함수(ex, 여기서 e는 자연로그의 밑)의 값을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +∞𝔽, return n.
  3. If n is either +0𝔽 or -0𝔽, return 1𝔽.
  4. If n is -∞𝔽, return +0𝔽.
  5. Return an implementation-approximated Number value representing the exponential function of (n).

21.3.2.15 Math.expm1 ( x )

이 함수는 ex에서 1을 뺀 결과를 반환한다. 결과는 x 값이 0에 가깝더라도 정확하도록 계산된다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, -0𝔽, or +∞𝔽, return n.
  3. If n is -∞𝔽, return -1𝔽.
  4. Let exp be the exponential function of (n).
  5. Return an implementation-approximated Number value representing exp - 1.

21.3.2.16 Math.floor ( x )

이 함수는 x보다 크지 않은 가장 큰( +∞에 가장 가까운) 정수 Number 값을 반환한다. 만약 x가 이미 정수 Number이면 결과는 x이다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0𝔽 or -0𝔽, return n.
  3. If n < 1𝔽 and n > +0𝔽, return +0𝔽.
  4. If n is an integral Number, return n.
  5. Return the greatest (closest to +∞) integral Number value that is not greater than n.
Note

Math.floor(x)의 값은 -Math.ceil(-x)의 값과 같다.

21.3.2.17 Math.fround ( x )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is one of +0𝔽, -0𝔽, +∞𝔽, or -∞𝔽, return n.
  4. Let n32 be the result of converting n to IEEE 754-2019 binary32 format using roundTiesToEven mode.
  5. Let n64 be the result of converting n32 to IEEE 754-2019 binary64 format.
  6. Return the ECMAScript Number value corresponding to n64.

21.3.2.18 Math.f16round ( x )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is NaN, return NaN.
  3. If n is one of +0𝔽, -0𝔽, +∞𝔽, or -∞𝔽, return n.
  4. Let n16 be the result of converting n to IEEE 754-2019 binary16 format using roundTiesToEven mode.
  5. Let n64 be the result of converting n16 to IEEE 754-2019 binary64 format.
  6. Return the ECMAScript Number value corresponding to n64.
Note

이 연산은 binary32로 캐스팅한 다음 binary16으로 캐스팅하는 것과 같지 않다(이중 반올림의 가능성 때문에): 예를 들어 k = 1.00048828125000022204𝔽에 대해 Math.f16round(k)는 1.0009765625𝔽이고, Math.f16round(Math.fround(k))는 1𝔽이다.

모든 플랫폼이 binary64에서 binary16으로의 네이티브 캐스팅을 제공하지는 않는다. 이를 제공할 수 있는 라이브러리들이 있으며, MIT 라이선스의 half 라이브러리가 그 예다. 또는 먼저 binary64를 roundTiesToEven 모드로 binary32로 캐스트한 다음, 결과가 잘못된 이중 반올림을 초래할 수 있는지 확인하고, 그런 경우에는 명시적으로 이들을 처리하여 올바른 결과가 나오도록 할 수 있다.

21.3.2.19 Math.hypot ( ...args )

0개 이상의 인수가 주어지면, 이 함수는 인수들의 제곱합의 제곱근을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let coerced be a new empty List.
  2. For each element arg of args, do
    1. Let n be ? ToNumber(arg).
    2. Append n to coerced.
  3. For each element number of coerced, do
    1. If number is either +∞𝔽 or -∞𝔽, return +∞𝔽.
  4. Let onlyZero be true.
  5. For each element number of coerced, do
    1. If number is NaN, return NaN.
    2. If number is neither +0𝔽 nor -0𝔽, set onlyZero to false.
  6. If onlyZero is true, return +0𝔽.
  7. Return an implementation-approximated Number value representing the square root of the sum of squares of the mathematical values of the elements of coerced.

이 함수의 "length" 속성은 2𝔽이다.

Note

구현체는 이 함수가 두 개 이상의 인수와 함께 호출될 때 발생하기 쉬운 오버플로우와 언더플로우로 인한 정밀도 손실을 피하기 위해 주의해야 한다.

21.3.2.20 Math.imul ( x, y )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Let a be (? ToUint32(x)).
  2. Let b be (? ToUint32(y)).
  3. Let product be (a × b) modulo 232.
  4. If product ≥ 231, return 𝔽(product - 232).
  5. Return 𝔽(product).

21.3.2.21 Math.log ( x )

이 함수는 x의 자연로그를 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +∞𝔽, return n.
  3. If n is 1𝔽, return +0𝔽.
  4. If n is either +0𝔽 or -0𝔽, return -∞𝔽.
  5. If n < -0𝔽, return NaN.
  6. Return an implementation-approximated Number value representing ln((n)).

21.3.2.22 Math.log1p ( x )

이 함수는 1 + x의 자연로그를 반환한다. 결과는 x 값이 0에 가까울 때도 정확하도록 계산된다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, -0𝔽, or +∞𝔽, return n.
  3. If n is -1𝔽, return -∞𝔽.
  4. If n < -1𝔽, return NaN.
  5. Return an implementation-approximated Number value representing ln(1 + (n)).

21.3.2.23 Math.log10 ( x )

이 함수는 x의 상용로그(밑10)를 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +∞𝔽, return n.
  3. If n is 1𝔽, return +0𝔽.
  4. If n is either +0𝔽 or -0𝔽, return -∞𝔽.
  5. If n < -0𝔽, return NaN.
  6. Return an implementation-approximated Number value representing log10((n)).

21.3.2.24 Math.log2 ( x )

이 함수는 x의 밑2 로그를 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is either NaN or +∞𝔽, return n.
  3. If n is 1𝔽, return +0𝔽.
  4. If n is either +0𝔽 or -0𝔽, return -∞𝔽.
  5. If n < -0𝔽, return NaN.
  6. Return an implementation-approximated Number value representing log2((n)).

21.3.2.25 Math.max ( ...args )

0개 이상의 인수가 주어지면, 이 함수는 각 인수에 ToNumber를 호출하고 그 결과 값들 중 가장 큰 값을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let coerced be a new empty List.
  2. For each element arg of args, do
    1. Let n be ? ToNumber(arg).
    2. Append n to coerced.
  3. Let highest be -∞𝔽.
  4. For each element number of coerced, do
    1. If number is NaN, return NaN.
    2. If number is +0𝔽 and highest is -0𝔽, set highest to +0𝔽.
    3. If number > highest, set highest to number.
  5. Return highest.
Note

가장 큰 값을 결정하기 위한 비교는 IsLessThan 알고리즘을 사용하되 +0𝔽-0𝔽보다 크다고 간주한다.

이 함수의 "length" 속성은 2𝔽이다.

21.3.2.26 Math.min ( ...args )

0개 이상의 인수가 주어지면, 이 함수는 각 인수에 ToNumber를 호출하고 그 결과 값들 중 가장 작은 값을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let coerced be a new empty List.
  2. For each element arg of args, do
    1. Let n be ? ToNumber(arg).
    2. Append n to coerced.
  3. Let lowest be +∞𝔽.
  4. For each element number of coerced, do
    1. If number is NaN, return NaN.
    2. If number is -0𝔽 and lowest is +0𝔽, set lowest to -0𝔽.
    3. If number < lowest, set lowest to number.
  5. Return lowest.
Note

가장 작은 값을 결정하기 위한 비교는 IsLessThan 알고리즘을 사용하되 +0𝔽-0𝔽보다 크다고 간주한다.

이 함수의 "length" 속성은 2𝔽이다.

21.3.2.27 Math.pow ( base, exponent )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. Set base to ? ToNumber(base).
  2. Set exponent to ? ToNumber(exponent).
  3. Return Number::exponentiate(base, exponent).

21.3.2.28 Math.random ( )

이 함수는 양의 부호를 갖고 +0𝔽 이상이면서 1𝔽 미만인 Number 값을 반환한다. 값은 구현 정의 알고리즘 또는 전략을 사용해 균등 분포에 근사하여 무작위 또는 의사무작위로 선택된다.

각 서로 다른 렐름(realm)에 대해 생성된 각 Math.random 함수는 연속 호출에서 서로 다른 값들의 수열을 생성해야 한다.

21.3.2.29 Math.round ( x )

이 함수는 x에 가장 가깝고 정수인 Number 값을 반환한다. 두 정수 값이 x에 대해 동일하게 가깝다면, 결과는 +∞에 더 가까운 Number 값이다. 만약 x가 이미 정수이면 결과는 x이다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is an integral Number, return n.
  3. If n < 0.5𝔽 and n > +0𝔽, return +0𝔽.
  4. If n < -0𝔽 and n-0.5𝔽, return -0𝔽.
  5. Return the integral Number closest to n, preferring the Number closer to +∞ in the case of a tie.
Note 1

Math.round(3.5)는 4를 반환하지만 Math.round(-3.5)는 -3을 반환한다.

Note 2

Math.round(x)의 값이 항상 Math.floor(x + 0.5)의 값과 같은 것은 아니다. x-0𝔽이거나 x-0𝔽보다 작지만 -0.5𝔽 이상이면, Math.round(x)-0𝔽를 반환하지만, Math.floor(x + 0.5)+0𝔽를 반환한다. 또한 Math.round(x)x + 0.5를 계산할 때의 내부 rounding 때문에 Math.floor(x + 0.5)의 값과 다를 수 있다.

21.3.2.30 Math.sign ( x )

이 함수는 x의 부호를 반환하여 x가 양수인지 음수인지 또는 0인지 나타낸다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n < -0𝔽, return -1𝔽.
  4. Return 1𝔽.

21.3.2.31 Math.sin ( x )

이 함수는 x의 사인을 반환한다. 인수는 라디안으로 표현된다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n is either +∞𝔽 or -∞𝔽, return NaN.
  4. Return an implementation-approximated Number value representing the sine of (n).

21.3.2.32 Math.sinh ( x )

이 함수는 x의 쌍곡사인을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0𝔽 or -0𝔽, return n.
  3. Return an implementation-approximated Number value representing the hyperbolic sine of (n).
Note

Math.sinh(x)의 값은 (Math.exp(x) - Math.exp(-x)) / 2의 값과 같다.

21.3.2.33 Math.sqrt ( x )

이 함수는 x의 제곱근을 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, -0𝔽, or +∞𝔽, return n.
  3. If n < -0𝔽, return NaN.
  4. Return 𝔽(the square root of (n)).

21.3.2.34 Math.sumPrecise ( items )

숫자들의 iterable이 주어지면, 이 함수는 iterable의 각 값을 합산하여 그 합을 반환한다. 만약 어떤 값이 Number가 아니면 TypeError 예외를 던진다.

호출될 때 다음 단계를 수행한다:

  1. Perform ? RequireObjectCoercible(items).
  2. Let iteratorRecord be ? GetIterator(items, sync).
  3. Let state be minus-zero.
  4. Let sum be 0.
  5. Let count be 0.
  6. Let next be not-started.
  7. Repeat, while next is not done,
    1. Set next to ? IteratorStepValue(iteratorRecord).
    2. If next is not done, then
      1. If count ≥ 253 - 1, then
        1. NOTE: This step is not expected to be reached in practice and is included only so that implementations may rely on inputs being "reasonably sized" without violating this specification.
        2. Let error be ThrowCompletion(a newly created RangeError object).
        3. Return ? IteratorClose(iteratorRecord, error).
      2. If next is not a Number, then
        1. Let error be ThrowCompletion(a newly created TypeError object).
        2. Return ? IteratorClose(iteratorRecord, error).
      3. Let n be next.
      4. If state is not not-a-number, then
        1. If n is NaN, then
          1. Set state to not-a-number.
        2. Else if n is +∞𝔽, then
          1. If state is minus-infinity, set state to not-a-number.
          2. Else, set state to plus-infinity.
        3. Else if n is -∞𝔽, then
          1. If state is plus-infinity, set state to not-a-number.
          2. Else, set state to minus-infinity.
        4. Else if n is not -0𝔽 and state is either minus-zero or finite, then
          1. Set state to finite.
          2. Set sum to sum + (n).
      5. Set count to count + 1.
  8. If state is not-a-number, return NaN.
  9. If state is plus-infinity, return +∞𝔽.
  10. If state is minus-infinity, return -∞𝔽.
  11. If state is minus-zero, return -0𝔽.
  12. Return 𝔽(sum).
Note

sum의 값은 임의 정밀도 산술 없이 다양한 알고리즘으로 계산할 수 있다. 한 가지는 Jonathan Richard Shewchuk의 "Grow-Expansion" 알고리즘이다. 보다 최근 알고리즘은 "Fast exact summation using small and large superaccumulators"이며, 코드가 https://gitlab.com/radfordneal/xsum에 있다.

21.3.2.35 Math.tan ( x )

이 함수는 x의 탄젠트를 반환한다. 인수는 라디안으로 표현된다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n is either +∞𝔽 or -∞𝔽, return NaN.
  4. Return an implementation-approximated Number value representing the tangent of (n).

21.3.2.36 Math.tanh ( x )

이 함수는 x의 쌍곡탄젠트를 반환한다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is one of NaN, +0𝔽, or -0𝔽, return n.
  3. If n is +∞𝔽, return 1𝔽.
  4. If n is -∞𝔽, return -1𝔽.
  5. Return an implementation-approximated Number value representing the hyperbolic tangent of (n).
Note

Math.tanh(x)의 값은 (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x))의 값과 같다.

21.3.2.37 Math.trunc ( x )

이 함수는 숫자 x정수 부분을 반환하여 소수 자릿수를 제거한다. 만약 x가 이미 정수이면 결과는 x이다.

호출될 때 다음 단계를 수행한다:

  1. Let n be ? ToNumber(x).
  2. If n is not finite or n is either +0𝔽 or -0𝔽, return n.
  3. If n < 1𝔽 and n > +0𝔽, return +0𝔽.
  4. If n < -0𝔽 and n > -1𝔽, return -0𝔽.
  5. Return the integral Number nearest n in the direction of +0𝔽.

21.4 Date 객체

21.4.1 Date 객체 개요 및 추상 연산 정의

다음의 추상 연산들은 시간 값들( 21.4.1.1에 정의됨 )에 대해 동작한다. 모든 경우에, 이러한 함수들의 어떤 인수가 NaN이면 결과는 NaN이 된다는 점에 유의하라.

21.4.1.1 시간 값들과 시간 범위

ECMAScript에서 시간 측정은 POSIX의 시간 측정과 유사하며, 특히 윤년 규칙을 사용하는 보정된 필요(프로레프틱) 그레고리력, 에포크(epoch)로 UTC 1970년 1월 1일 자정의 정의, 그리고 하루를 정확히 86,400초(각각 1000밀리초)로 계산하는 것을 공유한다.

ECMAScript에서 시간 값(time value)은 Number이다. 이는 밀리초 정밀도의 순간을 나타내는 유한정수 Number이거나 특정 순간을 나타내지 않는 NaN이다. 만약 시간 값이 24 × 60 × 60 × 1000 = 86,400,000의 배수(즉 86,400,000 × d 꼴의 정수 d)이면, 이는 에포크 이후 정수 d일의 시작에 해당하는 UTC 날짜의 순간을 나타낸다(음수 d의 경우 에포크보다 이전). 그 외의 모든 유한 시간 값 t는 그러한 배수인 가장 큰 이전의 시간 값 s에 대해 정의되며, 같은 UTC 날에 속하고 s 다음으로 (t - s) 밀리초만큼 뒤에 발생하는 순간을 나타낸다.

시간 값들은 UTC 윤초(leap seconds)를 고려하지 않는다—양의 윤초 안에 있는 순간을 나타내는 시간 값은 없고, 음의 윤초로 인해 UTC 타임라인에서 제거된 순간을 나타내는 시간 값은 존재할 수 있다. 하지만 시간 값의 정의는 윤초 경계에서만 불연속성을 갖고 윤초 밖에서는 차이가 0이므로 UTC와 부분적으로 정렬되는 결과를 낳는다.

Number는 -9,007,199,254,740,992에서 9,007,199,254,740,992까지의 정수를 정확히 표현할 수 있다(21.1.2.821.1.2.6). 시간 값은 약간 더 작은 범위인 밀리초 단위로 -8,640,000,000,000,000에서 8,640,000,000,000,000까지를 지원한다. 이는 에포크를 기준으로 정확히 -100,000,000일에서 100,000,000일까지의 지원 시간 값 범위를 제공한다.

1970년 1월 1일 자정의 정확한 순간은 시간 값 +0𝔽으로 표현된다.

Note

프로레프틱 그레고리력에서 윤년은 정확히 4로 나누어떨어지고 또한 400으로 나누어떨어지거나 100으로 나누어떨어지지 않는 해들이다.

400년 주기에는 97개의 윤년이 있다. 이는 연평균 365.2425일, 즉 31,556,952,000밀리초를 낳는다. 따라서 Number가 밀리초 정밀도로 정확히 표현할 수 있는 최대 범위는 대략 1970년을 기준으로 -285,426년에서 285,426년이다. 이 절에서 지정한 시간 값의 더 작은 범위는 약 1970년을 기준으로 -273,790년에서 273,790년이다.

21.4.1.2 시간 관련 상수들

다음 상수들은 이후 섹션들의 알고리즘에서 참조된다.

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 ( t )

The abstract operation Day takes argument t (a finite time value) and returns an integral Number. 이는 t가 속하는 날의 일 번호를 반환한다. It performs the following steps when called:

  1. Return 𝔽(floor((t / msPerDay))).

21.4.1.4 TimeWithinDay ( t )

The abstract operation TimeWithinDay takes argument t (a finite time value) and returns an integral Number in the interval from +0𝔽 (inclusive) to msPerDay (exclusive). 이는 t가 속하는 날의 시작 이후 경과한 밀리초 수를 반환한다. It performs the following steps when called:

  1. Return 𝔽((t) modulo (msPerDay)).

21.4.1.5 DaysInYear ( y )

The abstract operation DaysInYear takes argument y (an integral Number) and returns 365𝔽 or 366𝔽. 이는 연도 y의 일 수를 반환한다. 윤년은 366일이고, 그 외의 해는 365일이다. It performs the following steps when called:

  1. Let ry be (y).
  2. If (ry modulo 400) = 0, return 366𝔽.
  3. If (ry modulo 100) = 0, return 365𝔽.
  4. If (ry modulo 4) = 0, return 366𝔽.
  5. Return 365𝔽.

21.4.1.6 DayFromYear ( y )

The abstract operation DayFromYear takes argument y (an integral Number) and returns an integral Number. 이는 연도 y의 첫날의 일 번호를 반환한다. It performs the following steps when called:

  1. Let ry be (y).
  2. NOTE: In the following steps, numYears1, numYears4, numYears100, and numYears400 represent the number of years divisible by 1, 4, 100, and 400, respectively, that occur between the epoch and the start of year y. The number is negative if y is before the epoch.
  3. Let numYears1 be (ry - 1970).
  4. Let numYears4 be floor((ry - 1969) / 4).
  5. Let numYears100 be floor((ry - 1901) / 100).
  6. Let numYears400 be floor((ry - 1601) / 400).
  7. Return 𝔽(365 × numYears1 + numYears4 - numYears100 + numYears400).

21.4.1.7 TimeFromYear ( y )

The abstract operation TimeFromYear takes argument y (an integral Number) and returns a time value. 이는 연도 y의 시작 시각의 시간 값을 반환한다. It performs the following steps when called:

  1. Return msPerDay × DayFromYear(y).

21.4.1.8 YearFromTime ( t )

The abstract operation YearFromTime takes argument t (a finite time value) and returns an integral Number. 이는 t가 속하는 연도를 반환한다. It performs the following steps when called:

  1. Return the largest integral Number y (closest to +∞) such that TimeFromYear(y) ≤ t.

21.4.1.9 DayWithinYear ( t )

The abstract operation DayWithinYear takes argument t (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. Return Day(t) - DayFromYear(YearFromTime(t)).

21.4.1.10 InLeapYear ( t )

The abstract operation InLeapYear takes argument t (a finite time value) and returns +0𝔽 or 1𝔽. 이는 t가 윤년 내에 있으면 1𝔽을, 그렇지 않으면 +0𝔽을 반환한다. It performs the following steps when called:

  1. If DaysInYear(YearFromTime(t)) is 366𝔽, return 1𝔽.
  2. Return +0𝔽.

21.4.1.11 MonthFromTime ( t )

The abstract operation MonthFromTime takes argument t (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 11𝔽. 이는 t가 속하는 달을 식별하는 Number를 반환한다. 달 값 +0𝔽는 1월, 1𝔽는 2월, ..., 11𝔽는 12월을 지정한다. 참고로 MonthFromTime(+0𝔽) = +0𝔽는 1970년 1월 1일 목요일에 해당한다. It performs the following steps when called:

  1. Let inLeapYear be InLeapYear(t).
  2. Let dayWithinYear be DayWithinYear(t).
  3. If dayWithinYear < 31𝔽, return +0𝔽.
  4. If dayWithinYear < 59𝔽 + inLeapYear, return 1𝔽.
  5. If dayWithinYear < 90𝔽 + inLeapYear, return 2𝔽.
  6. If dayWithinYear < 120𝔽 + inLeapYear, return 3𝔽.
  7. If dayWithinYear < 151𝔽 + inLeapYear, return 4𝔽.
  8. If dayWithinYear < 181𝔽 + inLeapYear, return 5𝔽.
  9. If dayWithinYear < 212𝔽 + inLeapYear, return 6𝔽.
  10. If dayWithinYear < 243𝔽 + inLeapYear, return 7𝔽.
  11. If dayWithinYear < 273𝔽 + inLeapYear, return 8𝔽.
  12. If dayWithinYear < 304𝔽 + inLeapYear, return 9𝔽.
  13. If dayWithinYear < 334𝔽 + inLeapYear, return 10𝔽.
  14. Assert: dayWithinYear < 365𝔽 + inLeapYear.
  15. Return 11𝔽.

21.4.1.12 DateFromTime ( t )

The abstract operation DateFromTime takes argument t (a finite time value) and returns an integral Number in the inclusive interval from 1𝔽 to 31𝔽. 이는 t가 속하는 달의 날짜(일)를 반환한다. It performs the following steps when called:

  1. Let inLeapYear be InLeapYear(t).
  2. Let dayWithinYear be DayWithinYear(t).
  3. Let month be MonthFromTime(t).
  4. If month is +0𝔽, return dayWithinYear + 1𝔽.
  5. If month is 1𝔽, return dayWithinYear - 30𝔽.
  6. If month is 2𝔽, return dayWithinYear - 58𝔽 - inLeapYear.
  7. If month is 3𝔽, return dayWithinYear - 89𝔽 - inLeapYear.
  8. If month is 4𝔽, return dayWithinYear - 119𝔽 - inLeapYear.
  9. If month is 5𝔽, return dayWithinYear - 150𝔽 - inLeapYear.
  10. If month is 6𝔽, return dayWithinYear - 180𝔽 - inLeapYear.
  11. If month is 7𝔽, return dayWithinYear - 211𝔽 - inLeapYear.
  12. If month is 8𝔽, return dayWithinYear - 242𝔽 - inLeapYear.
  13. If month is 9𝔽, return dayWithinYear - 272𝔽 - inLeapYear.
  14. If month is 10𝔽, return dayWithinYear - 303𝔽 - inLeapYear.
  15. Assert: month is 11𝔽.
  16. Return dayWithinYear - 333𝔽 - inLeapYear.

21.4.1.13 WeekDay ( t )

The abstract operation WeekDay takes argument t (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 6𝔽. 이는 t가 속하는 요일을 식별하는 Number를 반환한다. 요일 값 +0𝔽는 일요일, 1𝔽는 월요일, ..., 6𝔽는 토요일을 지정한다. 참고로 WeekDay(+0𝔽) = 4𝔽는 1970년 1월 1일 목요일에 해당한다. It performs the following steps when called:

  1. Return 𝔽((Day(t) + 4𝔽) modulo 7).

21.4.1.14 HourFromTime ( t )

The abstract operation HourFromTime takes argument t (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 23𝔽. 이는 t가 속하는 시간(시)을 반환한다. It performs the following steps when called:

  1. Return 𝔽(floor((t / msPerHour)) modulo HoursPerDay).

21.4.1.15 MinFromTime ( t )

The abstract operation MinFromTime takes argument t (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 59𝔽. 이는 t가 속하는 분(minutes)을 반환한다. It performs the following steps when called:

  1. Return 𝔽(floor((t / msPerMinute)) modulo MinutesPerHour).

21.4.1.16 SecFromTime ( t )

The abstract operation SecFromTime takes argument t (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 59𝔽. 이는 t가 속하는 초(seconds)를 반환한다. It performs the following steps when called:

  1. Return 𝔽(floor((t / msPerSecond)) modulo SecondsPerMinute).

21.4.1.17 msFromTime ( t )

The abstract operation msFromTime takes argument t (a finite time value) and returns an integral Number in the inclusive interval from +0𝔽 to 999𝔽. 이는 t가 속하는 초의 밀리초 부분을 반환한다. It performs the following steps when called:

  1. Return 𝔽((t) 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. 반환 값은 주어진 ISO 8601 달력 날짜와 UTC의 벽 시계(wall-clock) 시각에 대응하는 에포크 이후의 나노초 수를 나타내는 BigInt이다. It performs the following steps when called:

  1. Let date be MakeDay(𝔽(year), 𝔽(month - 1), 𝔽(day)).
  2. Let time be MakeTime(𝔽(hour), 𝔽(minute), 𝔽(second), 𝔽(millisecond)).
  3. Let ms be MakeDate(date, time).
  4. Assert: ms is an integral Number.
  5. Return ((ms) × 106 + microsecond × 103 + nanosecond).

21.4.1.19 표준시(타임존) 식별자

ECMAScript에서 표준시(time zones)는 0x0000에서 0x007F 범위의 코드 유닛들로만 구성된 문자열인 타임존 식별자로 표현된다. 구현체가 지원하는 타임존은 사용 가능한 명명된 타임존(available named time zones) 또는 오프셋 타임존(offset time zones)일 수 있다. 오프셋 타임존은 IsTimeZoneOffsetString이 참을 반환하는 문자열로 표현된다.

주요(Primary) 타임존 식별자는 사용 가능한 명명된 타임존에 대한 선호 식별자이다. 비주요(Non-primary) 타임존 식별자는 주요 식별자가 아닌 사용 가능한 명명된 타임존의 식별자이다. 사용 가능한 명명된 타임존 식별자은 주요 식별자 또는 비주요 식별자이다. 각각의 사용 가능한 명명된 타임존 식별자는 정확히 하나의 사용 가능한 명명된 타임존과 연관된다. 각각의 사용 가능한 명명된 타임존은 정확히 하나의 주요 타임존 식별자와 0개 이상의 비주요 타임존 식별자와 연관된다.

ECMAScript 구현체는 식별자 "UTC"인 사용 가능한 명명된 타임존을 반드시 지원해야 하며, 이는 UTC 타임존의 주요 타임존 식별자여야 한다. 추가로, 구현체는 다른 많은 사용 가능한 명명된 타임존을 지원할 수 있다.

ECMA-402 국제화 API 요구사항을 따르는 구현체는 타임존 인식(time zone aware)이라고 불린다. 타임존 인식 구현체는 IANA 타임존 데이터베이스의 Zone 및 Link 이름에 해당하는 사용 가능한 명명된 타임존들을 지원해야 하며, 그 외의 이름을 지원해서는 안 된다. 타임존 인식 구현체에서 주요 타임존 식별자는 IANA Time Zone Database의 Zone 이름이고, 비주요 식별자는 Link 이름이다(ECMA-402 명세에서 AvailableNamedTimeZoneIdentifiers로 구체적으로 재정의되지 않는 한). 전체 IANA 타임존 데이터베이스를 지원하지 않는 구현체라도 IANA 이름을 식별자로 사용하는 것이 권장된다.

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. 반환되는 리스트의 각 값은 주어진 ISO 8601 달력 날짜와 명명된 타임존 timeZoneIdentifier에 해당하는 벽 시계 시각에 대응하는 에포크 이후의 나노초 수를 나타낸다.

입력이 음의 타임존 전환(예: 서머타임 종료로 시간이 반복되거나 타임존 규칙 변경으로 오프셋이 감소하는 경우)으로 인해 두 번 발생하는 지역 시간일 때, 반환 리스트는 두 개 이상의 요소를 가지며 오름차순으로 정렬된다. 입력이 양의 타임존 전환(예: 서머타임 시작으로 시간이 건너뛰어지거나 타임존 규칙 변경으로 오프셋이 증가하는 경우)으로 인해 건너뛰어진 지역 시간이라면, 반환 리스트는 비어있다. 그렇지 않으면 반환 리스트는 한 요소를 가진다.

GetNamedTimeZoneEpochNanoseconds의 기본 구현(로컬 정치적 규칙을 포함하지 않는 ECMAScript 구현체가 사용할)은 호출될 때 다음 단계를 수행한다:

  1. Assert: timeZoneIdentifier is "UTC".
  2. Let epochNanoseconds be GetUTCEpochNanoseconds(year, month, day, hour, minute, second, millisecond, microsecond, nanosecond).
  3. Return « epochNanoseconds ».
Note

타임존 인식 구현체(및 권장되는 다른 구현체들)는 IANA Time Zone Database의 시간대 정보를 사용하는 것이 요구된다: https://www.iana.org/time-zones/.

예: 2017년 11월 5일 1:30 AM America/New_York는 두 번 반복되므로 GetNamedTimeZoneEpochNanoseconds("America/New_York", 2017, 11, 5, 1, 30, 0, 0, 0, 0)는 길이 2의 리스트를 반환하며, 첫 번째 요소는 05:30 UTC(UTC 오프셋 -04:00에 해당하는 01:30 미국 동부 일광 절약 시간)를, 두 번째 요소는 06:30 UTC(01:30 미국 동부 표준시, 오프셋 -05:00)를 나타낸다.

2017년 3월 12일 2:30 AM America/New_York은 존재하지 않으므로 GetNamedTimeZoneEpochNanoseconds("America/New_York", 2017, 3, 12, 2, 30, 0, 0, 0, 0)는 빈 리스트를 반환한다.

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.

반환된 정수는 지정된 명명된 타임존 timeZoneIdentifier에 대해, 에포크로부터의 epochNanoseconds에 대응하는 순간에서의 UTC로부터의 오프셋을 나노초 단위로 나타낸다.

로컬 정치적 규칙을 포함하지 않는 구현체에서 사용할 GetNamedTimeZoneOffsetNanoseconds의 기본 구현은 호출될 때 다음 단계를 수행한다:

  1. Assert: timeZoneIdentifier is "UTC".
  2. Return 0.
Note

타임존 오프셋 값은 양수 또는 음수일 수 있다.

21.4.1.22 타임존 식별자 레코드

타임존 식별자 레코드사용 가능한 명명된 타임존 식별자와 해당 주요 타임존 식별자를 설명하기 위해 사용되는 레코드이다.

타임존 식별자 레코드는 Table 59에 열거된 필드를 가진다.

Table 59: 타임존 식별자 레코드 필드
필드 이름 의미
[[Identifier]] a String 구현체가 지원하는 사용 가능한 명명된 타임존 식별자.
[[PrimaryIdentifier]] a String [[Identifier]]가 해석하는 주요 타임존 식별자.
Note

만약 [[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. 반환 결과는 이 구현체에서 사용 가능한 모든 명명된 타임존 식별자들과 각 사용 가능한 식별자에 대응하는 주요 타임존 식별자를 설명한다. 리스트는 각 타임존 레코드의 [[Identifier]] 필드에 따라 정렬된다.

ECMA-402 국제화 API를 구현하는 타임존 인식 구현체는 AvailableNamedTimeZoneIdentifiers 추상 연산을 ECMA-402 명세에 지정된 대로 구현해야 한다. 타임존 인식이 아닌 구현체에 대해서는 AvailableNamedTimeZoneIdentifiers는 호출될 때 다음 단계를 수행한다:

  1. If the implementation does not include local political rules for any time zones, then
    1. Return « the Time Zone Identifier Record { [[Identifier]]: "UTC", [[PrimaryIdentifier]]: "UTC" } ».
  2. Let identifiers be the List of unique available named time zone identifiers, sorted according to lexicographic code unit order.
  3. Let result be a new empty List.
  4. For each element identifier of identifiers, do
    1. Let primary be identifier.
    2. If identifier is a non-primary time zone identifier in this implementation and identifier is not "UTC", then
      1. Set primary to the primary time zone identifier associated with identifier.
      2. NOTE: An implementation may need to resolve identifier iteratively to obtain the primary time zone identifier.
    3. Let record be the Time Zone Identifier Record { [[Identifier]]: identifier, [[PrimaryIdentifier]]: primary }.
    4. Append record to result.
  5. Assert: result contains a Time Zone Identifier Record r such that r.[[Identifier]] is "UTC" and r.[[PrimaryIdentifier]] is "UTC".
  6. Return result.

21.4.1.24 SystemTimeZoneIdentifier ( )

The implementation-defined abstract operation SystemTimeZoneIdentifier takes no arguments and returns a String. 이는 호스트 환경의 현재 타임존을 나타내는 문자열을 반환한다. 그 문자열은 IsTimeZoneOffsetString이 참을 반환하는 UTC 오프셋을 나타내는 문자열이거나 주요 타임존 식별자 중 하나이다. It performs the following steps when called:

  1. If the implementation only supports the UTC time zone, return "UTC".
  2. Let systemTimeZoneString be the String representing the host environment's current time zone, either a primary time zone identifier or an offset time zone identifier.
  3. Return systemTimeZoneString.
Note

Date 객체의 메서드들이 일반적으로 제공하는 수준의 기능을 보장하기 위해, SystemTimeZoneIdentifier는 가능하다면 호스트 환경의 시간대 설정에 대응하는 IANA 타임존 이름을 반환하는 것이 권장된다. GetNamedTimeZoneEpochNanosecondsGetNamedTimeZoneOffsetNanoseconds는 해당 타임존의 표준시 및 서머타임에 대한 로컬 정치적 규칙을 반영해야 한다(존재한다면).

예: 호스트 환경이 사용자가 US 동부 시간을 선택한 시스템 상의 브라우저라면, SystemTimeZoneIdentifier는 "America/New_York"을 반환한다.

21.4.1.25 LocalTime ( t )

The abstract operation LocalTime takes argument t (a finite time value) and returns an integral Number. 이는 t를 UTC에서 로컬 시간으로 변환한다. 결과를 결정하기 위해 해당 시각에 적용되는 표준시 및 서머타임에 대한 로컬 정치적 규칙을 사용해야 한다. It performs the following steps when called:

  1. Let systemTimeZoneIdentifier be SystemTimeZoneIdentifier().
  2. If IsTimeZoneOffsetString(systemTimeZoneIdentifier) is true, then
    1. Let offsetNs be ParseTimeZoneOffsetString(systemTimeZoneIdentifier).
  3. Else,
    1. Let offsetNs be GetNamedTimeZoneOffsetNanoseconds(systemTimeZoneIdentifier, ((t) × 106)).
  4. Let offsetMs be truncate(offsetNs / 106).
  5. Return t + 𝔽(offsetMs).
Note 1

만약 구현체 내에 로컬 시각에 대한 정치적 규칙이 없으면, 결과는 t이다. 왜냐하면 SystemTimeZoneIdentifier"UTC"를 반환하고 GetNamedTimeZoneOffsetNanoseconds는 0을 반환하기 때문이다.

Note 2

이 절에서 요구되는 바와 같이 구현체는 IANA Time Zone Database의 시간대 정보를 사용하는 것이 요구되며(권장), 이를 통해 로컬 정치적 규칙을 반영해야 한다.

Note 3

음의 타임존 전환(예: 서머타임 종료)에서는 두 다른 입력 시간 값 tUTC들이 같은 로컬 시간 tlocal으로 변환될 수 있다(즉 반복되는 시간이 보인다).

LocalTime(UTC(tlocal))는 항상 tlocal과 같지 않을 수 있다. 마찬가지로 UTC(LocalTime(tUTC))는 항상 tUTC과 같지 않을 수 있다.

21.4.1.26 UTC ( t )

The abstract operation UTC takes argument t (a Number) and returns a time value. 이는 t를 로컬 시간에서 UTC 시간 값으로 변환한다. 결과를 결정하기 위해 해당 시각에 적용되는 표준시 및 서머타임에 대한 로컬 정치적 규칙을 사용해야 한다. It performs the following steps when called:

  1. If t is not finite, return NaN.
  2. Let systemTimeZoneIdentifier be SystemTimeZoneIdentifier().
  3. If IsTimeZoneOffsetString(systemTimeZoneIdentifier) is true, then
    1. Let offsetNs be ParseTimeZoneOffsetString(systemTimeZoneIdentifier).
  4. Else,
    1. Let possibleInstants be GetNamedTimeZoneEpochNanoseconds(systemTimeZoneIdentifier, (YearFromTime(t)), (MonthFromTime(t)) + 1, (DateFromTime(t)), (HourFromTime(t)), (MinFromTime(t)), (SecFromTime(t)), (msFromTime(t)), 0, 0).
    2. NOTE: The following steps ensure that when t represents local time repeating multiple times at a negative time zone transition (e.g. when the daylight saving time ends or the time zone adjustment is decreased due to a time zone rule change) or skipped local time at a positive time zone transition (e.g. when the daylight saving time starts or the time zone offset is increased due to a time zone rule change), t is interpreted using the time zone offset before the transition.
    3. If possibleInstants is not empty, then
      1. Let disambiguatedInstant be possibleInstants[0].
    4. Else,
      1. NOTE: t represents a local time skipped at a positive time zone transition (e.g. due to daylight saving time starting or a time zone rule change increasing the UTC offset).
      2. Let possibleInstantsBefore be GetNamedTimeZoneEpochNanoseconds(systemTimeZoneIdentifier, (YearFromTime(tBefore)), (MonthFromTime(tBefore)) + 1, (DateFromTime(tBefore)), (HourFromTime(tBefore)), (MinFromTime(tBefore)), (SecFromTime(tBefore)), (msFromTime(tBefore)), 0, 0), where tBefore is the largest integral Number < t for which possibleInstantsBefore is not empty (i.e., tBefore represents the last local time before the transition).
      3. Let disambiguatedInstant be the last element of possibleInstantsBefore.
    5. Let offsetNs be GetNamedTimeZoneOffsetNanoseconds(systemTimeZoneIdentifier, disambiguatedInstant).
  5. Let offsetMs be truncate(offsetNs / 106).
  6. Return t - 𝔽(offsetMs).

입력 t는 명목상 시간 값이지만 어떤 Number 값도 될 수 있다. 알고리즘은 시간 값 범위로 t를 제한해서는 안 되며, 이는 지역 UTC 오프셋과 관계없이 시간 값 범위의 경계에 해당하는 입력을 지원하기 위함이다. 예를 들어, 최대 시간 값은 8.64 × 1015로 "+275760-09-13T00:00:00Z"에 해당한다. 지역 시간대 오프셋이 그 순간 UTC보다 1시간 앞선 환경에서는, 이는 더 큰 입력 8.64 × 1015 + 3.6 × 106로 표현되며 "+275760-09-13T01:00:00+01:00"에 해당한다.

만약 구현체 내에 로컬 시각에 대한 정치적 규칙이 없으면, 결과는 t이다. 왜냐하면 SystemTimeZoneIdentifier"UTC"를 반환하고 GetNamedTimeZoneOffsetNanoseconds는 0을 반환하기 때문이다.

Note 1

타임존 인식 구현체(및 권장되는 다른 구현체들)는 IANA Time Zone Database의 시간대 정보를 사용하는 것이 요구된다.

2017년 11월 5일 1:30 AM America/New_York는 두 번 반복되지만(시계 되돌림), 그것은 1:30 AM UTC-04로 해석되어야 한다(UTC-05가 아니라). UTC(TimeClip(MakeDate(MakeDay(2017, 10, 5), MakeTime(1, 30, 0, 0)))), 여기서 offsetMs-4 × msPerHour이다.

2017년 3월 12일 2:30 AM America/New_York은 존재하지 않지만, 그것은 2:30 AM UTC-05(즉 3:30 AM UTC-04와 동등)로 해석되어야 한다. UTC(TimeClip(MakeDate(MakeDay(2017, 2, 12), MakeTime(2, 30, 0, 0)))), 여기서 offsetMs-5 × msPerHour이다.

Note 2

UTC(LocalTime(tUTC))는 항상 tUTC와 같지 않을 수 있다. 마찬가지로 LocalTime(UTC(tlocal))는 항상 tlocal와 같지 않을 수 있다.

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. 이는 밀리초 수를 계산한다. It performs the following steps when called:

  1. If hour is not finite, min is not finite, sec is not finite, or ms is not finite, return NaN.
  2. Let h be 𝔽(! ToIntegerOrInfinity(hour)).
  3. Let m be 𝔽(! ToIntegerOrInfinity(min)).
  4. Let s be 𝔽(! ToIntegerOrInfinity(sec)).
  5. Let milli be 𝔽(! ToIntegerOrInfinity(ms)).
  6. Return ((h × msPerHour + m × msPerMinute) + s × msPerSecond) + milli.
Note

MakeTime의 산술은 부동소수점 산술이며 결합법칙이 성립하지 않으므로 연산은 올바른 순서로 수행되어야 한다.

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)를 계산한다. It performs the following steps when called:

  1. If year is not finite, month is not finite, or date is not finite, return NaN.
  2. Let y be 𝔽(! ToIntegerOrInfinity(year)).
  3. Let m be 𝔽(! ToIntegerOrInfinity(month)).
  4. Let dt be 𝔽(! ToIntegerOrInfinity(date)).
  5. Let ym be y + 𝔽(floor((m) / 12)).
  6. If ym is not finite, return NaN.
  7. Let mn be 𝔽((m) modulo 12).
  8. Find a finite time value t such that YearFromTime(t) is ym, MonthFromTime(t) is mn, and DateFromTime(t) is 1𝔽; but if this is not possible (because some argument is out of range), return NaN.
  9. Return Day(t) + 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. 이는 밀리초 수를 계산한다. It performs the following steps when called:

  1. If day is not finite or time is not finite, return NaN.
  2. Let tv be day × msPerDay + time.
  3. If tv is not finite, return NaN.
  4. Return tv.

21.4.1.30 MakeFullYear ( year )

The abstract operation MakeFullYear takes argument year (a Number) and returns an integral Number or NaN. 이는 year정수 부분과 연관된 완전 연도(full year)를 반환한다. 0에서 99 사이의 값은 1900년 시작 이후의 연도로 해석된다. 프로레프틱 그레고리력과 정렬을 위해 "full year"는 연도 0(기원전 1년) 시작 이후의 전체 연도 수로 정의된다. It performs the following steps when called:

  1. If year is one of NaN, +∞𝔽, or -∞𝔽, return NaN.
  2. Let truncated be ! ToIntegerOrInfinity(year).
  3. If truncated is in the inclusive interval from 0 to 99, return 1900𝔽 + 𝔽(truncated).
  4. Return 𝔽(truncated).

21.4.1.31 TimeClip ( time )

The abstract operation TimeClip takes argument time (a Number) and returns a time value. 이는 밀리초 수를 계산한다. It performs the following steps when called:

  1. If time is not finite, return NaN.
  2. If abs((time)) > 8.64 × 1015, return NaN.
  3. Return 𝔽(! ToIntegerOrInfinity(time)).

21.4.1.32 Date Time String Format

ECMAScript는 ISO 8601 달력 날짜 확장 형식의 단순화에 기반한 날짜-시간 문자열 교환 포맷을 정의한다. 형식은 다음과 같다: YYYY-MM-DDTHH:mm:ss.sssZ

요소들은 다음과 같다:

YYYY 프로레프틱 그레고리력에서 연도를 네 자리 십진수로 0000에서 9999까지 표현하거나, 확장 연도로서 부호(+) 또는 (-)와 여섯 자리 십진수를 사용하는 형태일 수 있다.
- 문자열 내에 문자 "-" (하이픈)이 두 번 문자 그대로 나타난다.
MM 연도의 월을 01(1월)에서 12(12월)까지 두 자리 십진수로 나타낸다.
DD 월의 일을 01에서 31까지 두 자리 십진수로 나타낸다.
T 시간 요소의 시작을 나타내기 위해 문자열에 "T"가 문자 그대로 나타난다.
HH 자정 이후 지난 완전한 시간 수를 00에서 24까지 두 자리 십진수로 나타낸다.
: 문자열 내에 문자 ":" (콜론)이 두 번 문자 그대로 나타난다.
mm 시간의 시작 이후의 완전한 분 수를 00에서 59까지 두 자리 십진수로 나타낸다.
ss 분의 시작 이후의 완전한 초 수를 00에서 59까지 두 자리 십진수로 나타낸다.
. 문자열 내에 문자 "." (점)이 문자 그대로 나타난다.
sss 초의 시작 이후의 완전한 밀리초 수를 세 자리 십진수로 나타낸다.
Z UTC 오프셋 표현으로 "Z" (오프셋 없는 UTC) 또는 "+" 또는 "-" 뒤에 시간 표현 HH:mm이 오는 형태로 지정된다(이는 로컬 시간이 UTC보다 앞서거나 뒤처짐을 나타내는 ISO 8601 타임존 오프셋 문자열 형식의 부분집합이다).

이 형식은 날짜 전용 형태도 포함한다:

YYYY
YYYY-MM
YYYY-MM-DD
        

또한 위의 날짜 전용 형태 중 하나에 선택적 UTC 오프셋 표현이 추가된 다음 시간 형태들 중 하나를 바로 이어붙인 “date-time” 형태들도 포함한다:

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

범위를 벗어나거나 형식에 맞지 않는 요소가 포함된 문자열은 이 형식의 유효한 인스턴스가 아니다.

Note 1

모든 날은 자정에서 시작하고 끝나므로 00:0024:00 두 표기법을 사용하여 하나 날짜와 연관된 두 자정을 구별할 수 있다. 이는 다음 두 표기가 정확히 동일한 시간을 가리킨다는 것을 의미한다: 1995-02-04T24:001995-02-05T00:00. 후자의 형태를 "날의 끝"으로 해석하는 것은 ISO 8601과 일치한다(ISO 8601은 시간 간격을 기술할 때 이를 예약하고 단일 시점을 표현할 때는 허용하지 않음에도 불구하고).

Note 2

CET, EST 등과 같은 민간 약어에 대한 국제 표준은 존재하지 않으며, 같은 약어가 서로 다른 타임존에 대해 사용되기도 한다. 이 이유로 ISO 8601과 이 형식은 모두 숫자 기반의 타임존 오프셋 표현을 지정한다.

21.4.1.32.1 확장 연도

시간 값 범위인 약 ±273,790년을 완전히 다루려면 9999년 이전 또는 이후의 연도를 표현해야 한다. ISO 8601은 연도 표기의 확장을 허용하지만 교환 당사자 간 합의에 의해서만 허용한다. 단순화된 ECMAScript 형식에서 그러한 확장 연도 표기는 6자리여야 하며 항상 + 또는 - 기호로 접두된다. 연도 0은 양수로 간주되어 반드시 + 기호로 접두되어야 한다. 연도 0을 -000000으로 표기하는 것은 유효하지 않다. 확장 연도를 사용한 Date Time String Format에 맞는 문자열이 시간 값 범위를 벗어나는 순간을 나타내면 Date.parse는 인식 불가능한 것으로 취급하고 구현체 특정 동작이나 휴리스틱에 의존하지 않고 NaN을 반환한다.

Note

확장 연도를 포함한 날짜-시간 값의 예:

-271821-04-20T00:00:00Z 기원전 271822년
-000001-01-01T00:00:00Z 기원전 2년
+000000-01-01T00:00:00Z 기원전 1년
+000001-01-01T00:00:00Z 서기 1년
+001970-01-01T00:00:00Z 서기 1970년
+002009-12-15T00:00:00Z 서기 2009년
+275760-09-13T00:00:00Z 서기 275760년

21.4.1.33 타임존 오프셋 문자열 형식

ECMAScript는 ISO 8601에서 파생된 UTC 오프셋을 위한 문자열 교환 형식을 정의한다. 형식은 다음 문법으로 설명된다.

문법

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. 반환값은 offsetStringUTCOffset 문법에 부합하는지 여부를 나타낸다. It performs the following steps when called:

  1. Let parseResult be ParseText(offsetString, UTCOffset).
  2. If parseResult is a List of errors, return false.
  3. Return true.

21.4.1.33.2 ParseTimeZoneOffsetString ( offsetString )

The abstract operation ParseTimeZoneOffsetString takes argument offsetString (a String) and returns an integer. 반환값은 문자열 offsetString에 해당하는 UTC 오프셋을 나노초 단위의 정수로 나타낸 것이다. It performs the following steps when called:

  1. parseResultParseText(offsetString, UTCOffset)라고 하자.
  2. Assert: parseResult는 오류의 List가 아니다.
  3. Assert: parseResultASCIISign Parse Node를 포함한다.
  4. parsedSignparseResult 안에 포함된 ASCIISign Parse Node와 일치한 소스 텍스트라고 하자.
  5. parsedSign이 단일 코드 포인트 U+002D (HYPHEN-MINUS)이면,
    1. sign을 -1이라고 하자.
  6. 그렇지 않으면,
    1. sign을 1이라고 하자.
  7. NOTE: 아래의 StringToNumber 적용은 정밀도를 잃지 않는다. 파싱된 각 값은 충분히 짧은 십진 숫자 문자열임이 보장되기 때문이다.
  8. Assert: parseResultHour Parse Node를 포함한다.
  9. parsedHoursparseResult 안에 포함된 Hour Parse Node와 일치한 소스 텍스트라고 하자.
  10. hours(StringToNumber(CodePointsToString(parsedHours)))라고 하자.
  11. parseResultMinuteSecond Parse Node를 포함하지 않으면,
    1. minutes를 0이라고 하자.
  12. 그렇지 않으면,
    1. parsedMinutesparseResult 안에 포함된 첫 번째 MinuteSecond Parse Node와 일치한 소스 텍스트라고 하자.
    2. minutes(StringToNumber(CodePointsToString(parsedMinutes)))라고 하자.
  13. parseResult가 두 개의 MinuteSecond Parse Node를 포함하지 않으면,
    1. seconds를 0이라고 하자.
  14. 그렇지 않으면,
    1. parsedSecondsparseResult 안에 포함된 두 번째 MinuteSecond Parse Node와 일치한 소스 텍스트라고 하자.
    2. seconds(StringToNumber(CodePointsToString(parsedSeconds)))라고 하자.
  15. parseResultTemporalDecimalFraction Parse Node를 포함하지 않으면,
    1. nanoseconds를 0이라고 하자.
  16. 그렇지 않으면,
    1. parsedFractionparseResult 안에 포함된 TemporalDecimalFraction Parse Node와 일치한 소스 텍스트라고 하자.
    2. fractionCodePointsToString(parsedFraction)과 "000000000"의 문자열 연결이라고 하자.
    3. nanosecondsStringfraction의 1부터 10까지의 부분 문자열이라고 하자.
    4. nanoseconds(StringToNumber(nanosecondsString))라고 하자.
  17. sign × (((hours × 60 + minutes) × 60 + seconds) × 109 + nanoseconds)를 반환한다.

21.4.2 Date 생성자

Date 생성자는:

  • %Date%이다.
  • 전역 객체"Date" 속성의 초기값이다.
  • 생성자로 호출될 때 새로운 Date를 생성하고 초기화한다.
  • 생성자가 아니라 함수로 호출될 때 현재 시간(UTC)을 나타내는 String을 반환한다.
  • 인자의 개수와 타입에 따라 동작이 달라지는 함수이다.
  • 클래스 정의의 extends 절의 값으로 사용될 수 있다. 지정된 Date 동작을 상속하려는 서브클래스 생성자는 [[DateValue]] 내부 슬롯을 가진 서브클래스 인스턴스를 생성하고 초기화하기 위해 Date 생성자에 대한 super 호출을 포함해야 한다.

21.4.2.1 Date ( ...values )

이 함수는 호출될 때 다음 단계를 수행한다:

  1. NewTarget이 undefined이면,
    1. now를 현재 시간을 식별하는 시간 값(UTC)이라고 하자.
    2. ToDateString(now)을 반환한다.
  2. numberOfArgsvalues의 요소 개수라고 하자.
  3. numberOfArgs = 0이면,
    1. dv를 현재 시간을 식별하는 시간 값(UTC)이라고 하자.
  4. 그렇지 않고 numberOfArgs = 1이면,
    1. valuevalues[0]이라고 하자.
    2. value가 Object이고 value[[DateValue]] 내부 슬롯을 가지면,
      1. tvvalue.[[DateValue]]라고 하자.
    3. 그렇지 않으면,
      1. v를 ? ToPrimitive(value)라고 하자.
      2. v가 String이면,
        1. Assert: 다음 단계는 v가 String이므로 abrupt completion을 결코 반환하지 않는다.
        2. tvparse 메서드(21.4.3.2)와 정확히 같은 방식으로 v를 날짜로 파싱한 결과라고 하자.
      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 Date 생성자의 속성

Date 생성자는:

  • 값이 %Function.prototype%[[Prototype]] 내부 슬롯을 가진다.
  • 값이 7𝔽"length" 속성을 가진다.
  • 다음 속성들을 가진다:

21.4.3.1 Date.now ( )

이 함수는 호출이 발생한 UTC 날짜와 시간을 지정하는 시간 값을 반환한다.

21.4.3.2 Date.parse ( string )

이 함수는 인자에 ToString 연산자를 적용한다. ToStringabrupt completion으로 끝나면 그 Completion Record가 즉시 반환된다. 그렇지 않으면 이 함수는 결과 String을 날짜와 시간으로 해석한다; 이 함수는 해당 날짜와 시간에 대응하는 UTC 시간 값인 Number를 반환한다. String은 그 내용에 따라 로컬 시간, UTC 시간, 또는 어떤 다른 시간대의 시간으로 해석될 수 있다. 이 함수는 먼저 확장 연도를 포함하여 Date Time String Format(21.4.1.32)에 설명된 형식에 따라 String을 파싱하려고 시도한다. String이 그 형식에 부합하지 않으면, 함수는 구현별 휴리스틱 또는 구현별 날짜 형식으로 대체할 수 있다. 인식할 수 없거나 범위를 벗어난 형식 요소 값을 포함하는 String은 이 함수가 NaN을 반환하게 해야 한다.

String이 Date Time String Format에 부합하면, 부재한 형식 요소를 대체 값이 대신한다. MM 또는 DD 요소가 부재하면 "01"이 사용된다. HH, mm, 또는 ss 요소가 부재하면 "00"이 사용된다. sss 요소가 부재하면 "000"이 사용된다. UTC 오프셋 표현이 부재하면, 날짜 전용 형식은 UTC 시간으로 해석되고 날짜-시간 형식은 로컬 시간으로 해석된다.

x가 ECMAScript의 특정 구현에서 밀리초 양이 0인 Date이면, 참조된 모든 속성이 초기값을 가진 경우, 다음 표현식들은 모두 그 구현에서 같은 숫자 값을 생성해야 한다:

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

그러나 표현식

Date.parse(x.toLocaleString())

은 앞의 세 표현식과 같은 Number 값을 생성할 필요가 없으며, 일반적으로 Date Time String Format(21.4.1.32)에 부합하지 않고 그 구현에서 toString 또는 toUTCString 메서드로 생성될 수 없는 임의의 String 값이 주어졌을 때 이 함수가 생성하는 값은 구현 정의이다.

21.4.3.3 Date.prototype

Date.prototype의 초기값은 Date 프로토타입 객체이다.

이 속성은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false } 속성 특성을 가진다.

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

이 함수는 호출될 때 다음 단계를 수행한다:

  1. y를 ? ToNumber(year)라고 하자.
  2. month가 존재하면 m을 ? ToNumber(month)라고 하자; 그렇지 않으면 m+0𝔽라고 하자.
  3. date가 존재하면 dt를 ? ToNumber(date)라고 하자; 그렇지 않으면 dt1𝔽라고 하자.
  4. hours가 존재하면 h를 ? ToNumber(hours)라고 하자; 그렇지 않으면 h+0𝔽라고 하자.
  5. minutes가 존재하면 min을 ? ToNumber(minutes)라고 하자; 그렇지 않으면 min+0𝔽라고 하자.
  6. seconds가 존재하면 s를 ? ToNumber(seconds)라고 하자; 그렇지 않으면 s+0𝔽라고 하자.
  7. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자; 그렇지 않으면 milli+0𝔽라고 하자.
  8. yrMakeFullYear(y)라고 하자.
  9. TimeClip(MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)))를 반환한다.

이 함수의 "length" 속성은 7𝔽이다.

Note

이 함수는 Date 생성자와 두 가지 면에서 다르다: Date를 생성하는 대신 시간 값을 Number로 반환하고, 인자를 로컬 시간이 아니라 UTC로 해석한다.

21.4.4 Date 프로토타입 객체의 속성

Date 프로토타입 객체는:

  • %Date.prototype%이다.
  • 그 자체가 보통 객체이다.
  • Date 인스턴스가 아니며 [[DateValue]] 내부 슬롯을 가지지 않는다.
  • 값이 %Object.prototype%[[Prototype]] 내부 슬롯을 가진다.

명시적으로 달리 정의되지 않는 한, 아래에 정의된 Date 프로토타입 객체의 메서드는 제네릭이 아니며, 그 메서드에 전달되는 this 값은 시간 값으로 초기화된 [[DateValue]] 내부 슬롯을 가진 객체여야 한다.

21.4.4.1 Date.prototype.constructor

Date.prototype.constructor의 초기값은 %Date%이다.

21.4.4.2 Date.prototype.getDate ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. DateFromTime(LocalTime(t))을 반환한다.

21.4.4.3 Date.prototype.getDay ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. WeekDay(LocalTime(t))를 반환한다.

21.4.4.4 Date.prototype.getFullYear ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. YearFromTime(LocalTime(t))를 반환한다.

21.4.4.5 Date.prototype.getHours ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. HourFromTime(LocalTime(t))를 반환한다.

21.4.4.6 Date.prototype.getMilliseconds ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. msFromTime(LocalTime(t))를 반환한다.

21.4.4.7 Date.prototype.getMinutes ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. MinFromTime(LocalTime(t))를 반환한다.

21.4.4.8 Date.prototype.getMonth ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. MonthFromTime(LocalTime(t))을 반환한다.

21.4.4.9 Date.prototype.getSeconds ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. SecFromTime(LocalTime(t))를 반환한다.

21.4.4.10 Date.prototype.getTime ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. dateObject.[[DateValue]]를 반환한다.

21.4.4.11 Date.prototype.getTimezoneOffset ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. (t - LocalTime(t)) / msPerMinute를 반환한다.

21.4.4.12 Date.prototype.getUTCDate ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. DateFromTime(t)를 반환한다.

21.4.4.13 Date.prototype.getUTCDay ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. WeekDay(t)를 반환한다.

21.4.4.14 Date.prototype.getUTCFullYear ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. YearFromTime(t)를 반환한다.

21.4.4.15 Date.prototype.getUTCHours ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. HourFromTime(t)를 반환한다.

21.4.4.16 Date.prototype.getUTCMilliseconds ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. msFromTime(t)를 반환한다.

21.4.4.17 Date.prototype.getUTCMinutes ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. MinFromTime(t)를 반환한다.

21.4.4.18 Date.prototype.getUTCMonth ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. MonthFromTime(t)을 반환한다.

21.4.4.19 Date.prototype.getUTCSeconds ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 NaN을 반환한다.
  5. SecFromTime(t)를 반환한다.

21.4.4.20 Date.prototype.setDate ( date )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. dt를 ? ToNumber(date)라고 하자.
  5. tNaN이면 NaN을 반환한다.
  6. tLocalTime(t)로 설정한다.
  7. newDateMakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t))라고 하자.
  8. uTimeClip(UTC(newDate))라고 하자.
  9. dateObject.[[DateValue]]u로 설정한다.
  10. u를 반환한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. y를 ? ToNumber(year)라고 하자.
  5. tNaN이면 t+0𝔽로 설정한다; 그렇지 않으면 tLocalTime(t)로 설정한다.
  6. month가 존재하면 m을 ? ToNumber(month)라고 하자; 그렇지 않으면 mMonthFromTime(t)라고 하자.
  7. date가 존재하면 dt를 ? ToNumber(date)라고 하자; 그렇지 않으면 dtDateFromTime(t)라고 하자.
  8. newDateMakeDate(MakeDay(y, m, dt), TimeWithinDay(t))라고 하자.
  9. uTimeClip(UTC(newDate))라고 하자.
  10. dateObject.[[DateValue]]u로 설정한다.
  11. u를 반환한다.

이 메서드의 "length" 속성은 3𝔽이다.

Note

month가 존재하지 않으면, 이 메서드는 monthgetMonth() 값을 가지고 존재하는 것처럼 동작한다. date가 존재하지 않으면, dategetDate() 값을 가지고 존재하는 것처럼 동작한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. h를 ? ToNumber(hour)라고 하자.
  5. min이 존재하면 m을 ? ToNumber(min)이라고 하자.
  6. sec이 존재하면 s를 ? ToNumber(sec)라고 하자.
  7. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자.
  8. tNaN이면 NaN을 반환한다.
  9. tLocalTime(t)로 설정한다.
  10. min이 존재하지 않으면 mMinFromTime(t)이라고 하자.
  11. sec이 존재하지 않으면 sSecFromTime(t)라고 하자.
  12. ms가 존재하지 않으면 millimsFromTime(t)라고 하자.
  13. dateMakeDate(Day(t), MakeTime(h, m, s, milli))라고 하자.
  14. uTimeClip(UTC(date))라고 하자.
  15. dateObject.[[DateValue]]u로 설정한다.
  16. u를 반환한다.

이 메서드의 "length" 속성은 4𝔽이다.

Note

min이 존재하지 않으면, 이 메서드는 mingetMinutes() 값을 가지고 존재하는 것처럼 동작한다. sec이 존재하지 않으면, secgetSeconds() 값을 가지고 존재하는 것처럼 동작한다. ms가 존재하지 않으면, msgetMilliseconds() 값을 가지고 존재하는 것처럼 동작한다.

21.4.4.23 Date.prototype.setMilliseconds ( ms )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. ms를 ? ToNumber(ms)로 설정한다.
  5. tNaN이면 NaN을 반환한다.
  6. tLocalTime(t)로 설정한다.
  7. timeMakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms)이라고 하자.
  8. uTimeClip(UTC(MakeDate(Day(t), time)))라고 하자.
  9. dateObject.[[DateValue]]u로 설정한다.
  10. u를 반환한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. m을 ? ToNumber(min)이라고 하자.
  5. sec이 존재하면 s를 ? ToNumber(sec)라고 하자.
  6. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자.
  7. tNaN이면 NaN을 반환한다.
  8. tLocalTime(t)로 설정한다.
  9. sec이 존재하지 않으면 sSecFromTime(t)라고 하자.
  10. ms가 존재하지 않으면 millimsFromTime(t)라고 하자.
  11. dateMakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli))라고 하자.
  12. uTimeClip(UTC(date))라고 하자.
  13. dateObject.[[DateValue]]u로 설정한다.
  14. u를 반환한다.

이 메서드의 "length" 속성은 3𝔽이다.

Note

sec이 존재하지 않으면, 이 메서드는 secgetSeconds() 값을 가지고 존재하는 것처럼 동작한다. ms가 존재하지 않으면, 이것은 msgetMilliseconds() 값을 가지고 존재하는 것처럼 동작한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. m을 ? ToNumber(month)이라고 하자.
  5. date가 존재하면 dt를 ? ToNumber(date)라고 하자.
  6. tNaN이면 NaN을 반환한다.
  7. tLocalTime(t)로 설정한다.
  8. date가 존재하지 않으면 dtDateFromTime(t)라고 하자.
  9. newDateMakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t))라고 하자.
  10. uTimeClip(UTC(newDate))라고 하자.
  11. dateObject.[[DateValue]]u로 설정한다.
  12. u를 반환한다.

이 메서드의 "length" 속성은 2𝔽이다.

Note

date가 존재하지 않으면, 이 메서드는 dategetDate() 값을 가지고 존재하는 것처럼 동작한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. s를 ? ToNumber(sec)라고 하자.
  5. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자.
  6. tNaN이면 NaN을 반환한다.
  7. tLocalTime(t)로 설정한다.
  8. ms가 존재하지 않으면 millimsFromTime(t)라고 하자.
  9. dateMakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli))라고 하자.
  10. uTimeClip(UTC(date))라고 하자.
  11. dateObject.[[DateValue]]u로 설정한다.
  12. u를 반환한다.

이 메서드의 "length" 속성은 2𝔽이다.

Note

ms가 존재하지 않으면, 이 메서드는 msgetMilliseconds() 값을 가지고 존재하는 것처럼 동작한다.

21.4.4.27 Date.prototype.setTime ( time )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. t를 ? ToNumber(time)라고 하자.
  4. vTimeClip(t)라고 하자.
  5. dateObject.[[DateValue]]v로 설정한다.
  6. v를 반환한다.

21.4.4.28 Date.prototype.setUTCDate ( date )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. dt를 ? ToNumber(date)라고 하자.
  5. tNaN이면 NaN을 반환한다.
  6. newDateMakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), dt), TimeWithinDay(t))라고 하자.
  7. vTimeClip(newDate)라고 하자.
  8. dateObject.[[DateValue]]v로 설정한다.
  9. v를 반환한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. tNaN이면 t+0𝔽로 설정한다.
  5. y를 ? ToNumber(year)라고 하자.
  6. month가 존재하면 m을 ? ToNumber(month)라고 하자; 그렇지 않으면 mMonthFromTime(t)라고 하자.
  7. date가 존재하면 dt를 ? ToNumber(date)라고 하자; 그렇지 않으면 dtDateFromTime(t)라고 하자.
  8. newDateMakeDate(MakeDay(y, m, dt), TimeWithinDay(t))라고 하자.
  9. vTimeClip(newDate)라고 하자.
  10. dateObject.[[DateValue]]v로 설정한다.
  11. v를 반환한다.

이 메서드의 "length" 속성은 3𝔽이다.

Note

month가 존재하지 않으면, 이 메서드는 monthgetUTCMonth() 값을 가지고 존재하는 것처럼 동작한다. date가 존재하지 않으면, dategetUTCDate() 값을 가지고 존재하는 것처럼 동작한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. h를 ? ToNumber(hour)라고 하자.
  5. min이 존재하면 m을 ? ToNumber(min)이라고 하자.
  6. sec이 존재하면 s를 ? ToNumber(sec)라고 하자.
  7. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자.
  8. tNaN이면 NaN을 반환한다.
  9. min이 존재하지 않으면 mMinFromTime(t)이라고 하자.
  10. sec이 존재하지 않으면 sSecFromTime(t)라고 하자.
  11. ms가 존재하지 않으면 millimsFromTime(t)라고 하자.
  12. dateMakeDate(Day(t), MakeTime(h, m, s, milli))라고 하자.
  13. vTimeClip(date)라고 하자.
  14. dateObject.[[DateValue]]v로 설정한다.
  15. v를 반환한다.

이 메서드의 "length" 속성은 4𝔽이다.

Note

min이 존재하지 않으면, 이 메서드는 mingetUTCMinutes() 값을 가지고 존재하는 것처럼 동작한다. sec이 존재하지 않으면, secgetUTCSeconds() 값을 가지고 존재하는 것처럼 동작한다. ms가 존재하지 않으면, msgetUTCMilliseconds() 값을 가지고 존재하는 것처럼 동작한다.

21.4.4.31 Date.prototype.setUTCMilliseconds ( ms )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. ms를 ? ToNumber(ms)로 설정한다.
  5. tNaN이면 NaN을 반환한다.
  6. timeMakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms)이라고 하자.
  7. vTimeClip(MakeDate(Day(t), time))라고 하자.
  8. dateObject.[[DateValue]]v로 설정한다.
  9. v를 반환한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. m을 ? ToNumber(min)이라고 하자.
  5. sec이 존재하면 s를 ? ToNumber(sec)라고 하자.
  6. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자.
  7. tNaN이면 NaN을 반환한다.
  8. sec이 존재하지 않으면 sSecFromTime(t)라고 하자.
  9. ms가 존재하지 않으면 millimsFromTime(t)라고 하자.
  10. dateMakeDate(Day(t), MakeTime(HourFromTime(t), m, s, milli))라고 하자.
  11. vTimeClip(date)라고 하자.
  12. dateObject.[[DateValue]]v로 설정한다.
  13. v를 반환한다.

이 메서드의 "length" 속성은 3𝔽이다.

Note

sec이 존재하지 않으면, 이 메서드는 secgetUTCSeconds() 값을 가지고 존재하는 것처럼 동작한다. ms가 존재하지 않으면, msgetUTCMilliseconds()가 반환한 값을 가지고 존재하는 것처럼 동작한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. m을 ? ToNumber(month)이라고 하자.
  5. date가 존재하면 dt를 ? ToNumber(date)라고 하자.
  6. tNaN이면 NaN을 반환한다.
  7. date가 존재하지 않으면 dtDateFromTime(t)라고 하자.
  8. newDateMakeDate(MakeDay(YearFromTime(t), m, dt), TimeWithinDay(t))라고 하자.
  9. vTimeClip(newDate)라고 하자.
  10. dateObject.[[DateValue]]v로 설정한다.
  11. v를 반환한다.

이 메서드의 "length" 속성은 2𝔽이다.

Note

date가 존재하지 않으면, 이 메서드는 dategetUTCDate() 값을 가지고 존재하는 것처럼 동작한다.

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

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tdateObject.[[DateValue]]라고 하자.
  4. s를 ? ToNumber(sec)라고 하자.
  5. ms가 존재하면 milli를 ? ToNumber(ms)라고 하자.
  6. tNaN이면 NaN을 반환한다.
  7. ms가 존재하지 않으면 millimsFromTime(t)라고 하자.
  8. dateMakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), s, milli))라고 하자.
  9. vTimeClip(date)라고 하자.
  10. dateObject.[[DateValue]]v로 설정한다.
  11. v를 반환한다.

이 메서드의 "length" 속성은 2𝔽이다.

Note

ms가 존재하지 않으면, 이 메서드는 msgetUTCMilliseconds() 값을 가지고 존재하는 것처럼 동작한다.

21.4.4.35 Date.prototype.toDateString ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tvdateObject.[[DateValue]]라고 하자.
  4. tvNaN이면 "Invalid Date"를 반환한다.
  5. tLocalTime(tv)라고 하자.
  6. DateString(t)를 반환한다.

21.4.4.36 Date.prototype.toISOString ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tvdateObject.[[DateValue]]라고 하자.
  4. tvNaN이면 RangeError 예외를 던진다.
  5. Assert: tv정수 Number이다.
  6. tvDate Time String Format으로 표현할 수 없는 연도에 대응하면, RangeError 예외를 던진다.
  7. 모든 형식 요소와 UTC 오프셋 표현 "Z"를 포함하여, UTC 시간 척도에서 Date Time String Formattv의 String 표현을 반환한다.

21.4.4.37 Date.prototype.toJSON ( key )

이 메서드는 JSON.stringify(25.5.4)에서 사용하기 위한 Date의 String 표현을 제공한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. obj를 ? ToObject(this value)라고 하자.
  2. tv를 ? ToPrimitive(obj, number)라고 하자.
  3. tv가 Number이고 tv유한하지 않으면 null을 반환한다.
  4. Invoke(obj, "toISOString")를 반환한다.
Note 1

인자는 무시된다.

Note 2

이 메서드는 의도적으로 제네릭이다; 이 메서드는 자신의 this 값이 Date일 것을 요구하지 않는다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 있다. 그러나 그러한 객체는 toISOString 메서드를 가져야 한다.

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

ECMA-402 국제화 API를 포함하는 ECMAScript 구현은 ECMA-402 명세에 지정된 대로 이 메서드를 구현해야 한다. ECMAScript 구현이 ECMA-402 API를 포함하지 않는 경우 이 메서드에 대한 다음 명세가 사용된다:

이 메서드는 String 값을 반환한다. String의 내용은 구현 정의이지만, 현재 시간대에서 Date의 “date” 부분을 호스트 환경의 현재 로캘 관례에 대응하는 편리하고 사람이 읽을 수 있는 형식으로 나타내도록 의도되어 있다.

이 메서드의 선택적 매개변수의 의미는 ECMA-402 명세에 정의되어 있다; ECMA-402 지원을 포함하지 않는 구현은 그 매개변수 위치를 다른 어떤 용도로도 사용해서는 안 된다.

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

ECMA-402 국제화 API를 포함하는 ECMAScript 구현은 ECMA-402 명세에 지정된 대로 이 메서드를 구현해야 한다. ECMAScript 구현이 ECMA-402 API를 포함하지 않는 경우 이 메서드에 대한 다음 명세가 사용된다:

이 메서드는 String 값을 반환한다. String의 내용은 구현 정의이지만, 현재 시간대의 Date를 호스트 환경의 현재 로캘 관례에 대응하는 편리하고 사람이 읽을 수 있는 형식으로 나타내도록 의도되어 있다.

이 메서드의 선택적 매개변수의 의미는 ECMA-402 명세에 정의되어 있다; ECMA-402 지원을 포함하지 않는 구현은 그 매개변수 위치를 다른 어떤 용도로도 사용해서는 안 된다.

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

ECMA-402 국제화 API를 포함하는 ECMAScript 구현은 ECMA-402 명세에 지정된 대로 이 메서드를 구현해야 한다. ECMAScript 구현이 ECMA-402 API를 포함하지 않는 경우 이 메서드에 대한 다음 명세가 사용된다:

이 메서드는 String 값을 반환한다. String의 내용은 구현 정의이지만, 현재 시간대에서 Date의 “time” 부분을 호스트 환경의 현재 로캘 관례에 대응하는 편리하고 사람이 읽을 수 있는 형식으로 나타내도록 의도되어 있다.

이 메서드의 선택적 매개변수의 의미는 ECMA-402 명세에 정의되어 있다; ECMA-402 지원을 포함하지 않는 구현은 그 매개변수 위치를 다른 어떤 용도로도 사용해서는 안 된다.

21.4.4.41 Date.prototype.toString ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tvdateObject.[[DateValue]]라고 하자.
  4. ToDateString(tv)을 반환한다.
Note 1

d.[[DateValue]]가 1000으로 나누어떨어지는 임의의 Date d에 대해, Date.parse(d.toString())의 결과 = d.valueOf()이다. 21.4.3.2를 보라.

Note 2

이 메서드는 제네릭이 아니다; 자신의 this 값이 Date가 아니면 TypeError 예외를 던진다. 따라서 메서드로 사용하기 위해 다른 종류의 객체로 이전될 수 없다.

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, 코드 단위 0x0020 (SPACE), 및 "GMT"의 문자열 연결을 반환한다.

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를 Number WeekDay(tv)를 가진 Table 60의 항목의 Name이라고 하자.
  2. month를 Number MonthFromTime(tv)를 가진 Table 61의 항목의 Name이라고 하자.
  3. dayToZeroPaddedDecimalString((DateFromTime(tv)), 2)라고 하자.
  4. yvYearFromTime(tv)라고 하자.
  5. yv+0𝔽이거나 yv > +0𝔽이면 yearSign을 빈 String이라고 하자; 그렇지 않으면 yearSign"-"라고 하자.
  6. paddedYearToZeroPaddedDecimalString(abs((yv)), 4)라고 하자.
  7. weekday, 코드 단위 0x0020 (SPACE), month, 코드 단위 0x0020 (SPACE), day, 코드 단위 0x0020 (SPACE), yearSign, 및 paddedYear의 문자열 연결을 반환한다.
Table 60: 요일 이름
Number Name
+0𝔽 "Sun"
1𝔽 "Mon"
2𝔽 "Tue"
3𝔽 "Wed"
4𝔽 "Thu"
5𝔽 "Fri"
6𝔽 "Sat"
Table 61: 월 이름
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을 빈 String이거나 코드 단위 0x0020 (SPACE), 코드 단위 0x0028 (LEFT PARENTHESIS), 구현 정의 시간대 이름, 및 코드 단위 0x0029 (RIGHT PARENTHESIS)의 문자열 연결인 구현 정의 문자열이라고 하자.
  10. offsetSign, offsetHour, offsetMin, 및 tzName의 문자열 연결을 반환한다.

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. tLocalTime(tv)라고 하자.
  3. DateString(t), 코드 단위 0x0020 (SPACE), TimeString(t), 및 TimeZoneString(tv)의 문자열 연결을 반환한다.

21.4.4.42 Date.prototype.toTimeString ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tvdateObject.[[DateValue]]라고 하자.
  4. tvNaN이면 "Invalid Date"를 반환한다.
  5. tLocalTime(tv)라고 하자.
  6. TimeString(t)와 TimeZoneString(tv)의 문자열 연결을 반환한다.

21.4.4.43 Date.prototype.toUTCString ( )

이 메서드는 this 값에 대응하는 시간상 순간을 나타내는 String 값을 반환한다. String의 형식은 RFC 7231의 "HTTP-date"에 기반하며, ECMAScript Dates가 지원하는 전체 시간 범위를 지원하도록 일반화되어 있다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. tvdateObject.[[DateValue]]라고 하자.
  4. tvNaN이면 "Invalid Date"를 반환한다.
  5. weekday를 Number WeekDay(tv)를 가진 Table 60의 항목의 Name이라고 하자.
  6. month를 Number MonthFromTime(tv)를 가진 Table 61의 항목의 Name이라고 하자.
  7. dayToZeroPaddedDecimalString((DateFromTime(tv)), 2)라고 하자.
  8. yvYearFromTime(tv)라고 하자.
  9. yv+0𝔽이거나 yv > +0𝔽이면 yearSign을 빈 String이라고 하자; 그렇지 않으면 yearSign"-"라고 하자.
  10. paddedYearToZeroPaddedDecimalString(abs((yv)), 4)라고 하자.
  11. weekday, ",", 코드 단위 0x0020 (SPACE), day, 코드 단위 0x0020 (SPACE), month, 코드 단위 0x0020 (SPACE), yearSign, paddedYear, 코드 단위 0x0020 (SPACE), 및 TimeString(tv)의 문자열 연결을 반환한다.

21.4.4.44 Date.prototype.valueOf ( )

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. dateObjectthis 값이라고 하자.
  2. RequireInternalSlot(dateObject, [[DateValue]])를 수행한다.
  3. dateObject.[[DateValue]]를 반환한다.

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

이 메서드는 ECMAScript 언어 연산자가 Date를 원시 값으로 변환하기 위해 호출한다. hint에 허용되는 값은 "default", "number", 및 "string"이다. Date는 내장 ECMAScript 객체들 중에서 "default""string"과 동등한 것으로 취급한다는 점에서 고유하다. 다른 모든 내장 ECMAScript 객체들은 "default""number"와 동등한 것으로 취급한다.

이 메서드는 호출될 때 다음 단계를 수행한다:

  1. objthis 값이라고 하자.
  2. obj가 Object가 아니면 TypeError 예외를 던진다.
  3. hint"string" 또는 "default" 중 하나이면,
    1. tryFirststring이라고 하자.
  4. 그렇지 않고 hint"number"이면,
    1. tryFirstnumber라고 하자.
  5. 그렇지 않으면,
    1. TypeError 예외를 던진다.
  6. OrdinaryToPrimitive(obj, tryFirst)를 반환한다.

이 속성은 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true } 속성 특성을 가진다.

이 메서드의 "name" 속성의 값은 "[Symbol.toPrimitive]"이다.

21.4.5 Date 인스턴스의 속성

Date 인스턴스는 Date 프로토타입 객체로부터 속성을 상속하는 보통 객체이다. Date 인스턴스는 또한 [[DateValue]] 내부 슬롯을 가진다. [[DateValue]] 내부 슬롯은 이 Date가 나타내는 시간 값이다.