ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 49

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     47      48      49      50     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 49

 

 

NOTE

When 

Math.imul

Math.imul

 is called with arguments 

x

 and 

y

, the following steps are taken:

1.  Let 

a

 be 

(? 

ToUint32

(

x

)).

2.  Let 

b

(? 

ToUint32

(

y

)).

3.  Let 

product

 be (

a

 

×

 

b

modulo

 2

32

.

4.  If 

product

 

 2

31

(

product

 - 2

32

); otherwise return 

(

product

).

Returns the natural logarithm of 

x

.

When the 

Math.log

Math.log

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

 or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

1

𝔽

, return 

+0

𝔽

.

4.  If 

n

 is 

+0

𝔽

 or 

n

 is 

-0

𝔽

, return 

-

𝔽

.

5.  If 

n

 < 

+0

𝔽

, return 

NaN

.

6.  Return an 

implementation-approximated

n

).

Returns the natural logarithm of 1 + 

x

. The result is computed in a way that is accurate even when the value of x is

close to zero.

When the 

Math.log1p

Math.log1p

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

, or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

-1

𝔽

, return 

-

𝔽

.

4.  If 

n

 < 

-1

𝔽

, return 

NaN

.

5.  Return an 

implementation-approximated

n

).

Returns the base 10 logarithm of 

x

.

When the 

Math.log10

Math.log10

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

 or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

1

𝔽

, return 

+0

𝔽

.

Implementations should take care to avoid the loss of precision from overflows and underflows
that are prone to occur in naive implementations when this function is called with two or more
arguments.

21.3.2.19  Math.imul ( 

x

y

 )

21.3.2.20  Math.log ( 

x

 )

21.3.2.21  Math.log1p ( 

x

 )

21.3.2.22  Math.log10 ( 

x

 )

525

4.  If 

n

 is 

+0

𝔽

 or 

n

 is 

-0

𝔽

, return 

-

𝔽

.

5.  If 

n

 < 

+0

𝔽

, return 

NaN

.

6.  Return an 

implementation-approximated

n

).

Returns the base 2 logarithm of 

x

.

When the 

Math.log2

Math.log2

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

 or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 is 

1

𝔽

, return 

+0

𝔽

.

4.  If 

n

 is 

+0

𝔽

 or 

n

 is 

-0

𝔽

, return 

-

𝔽

.

5.  If 

n

 < 

+0

𝔽

, return 

NaN

.

6.  Return an 

implementation-approximated

 value representing the result of the base 2 logarithm of 

n

).

Given zero or more arguments, calls 

ToNumber

 on each of the arguments and returns the largest of the resulting

values.

When the 

Math.max

Math.max

 method is called with zero or more arguments which form the rest parameter ...

args

, the

following steps are taken:

1.  Let 

coerced

 be a new empty 

List

.

2.  For each element 

arg

 of 

args

, do

a.  Let 

n

 be ? 

ToNumber

(

arg

).

b.  Append 

n

 to 

coerced

.

3.  Let 

highest

 be 

-

𝔽

.

4.  For each element 

number

 of 

coerced

, do

a.  If 

number

 is 

NaN

, return 

NaN

.

b.  If 

number

 is 

+0

𝔽

 and 

highest

 is 

-0

𝔽

, set 

highest

 to 

+0

𝔽

.

c.  If 

number

 > 

highest

, set 

highest

 to 

number

.

5.  Return 

highest

.

NOTE

The 

"length"

 property of the 

max

max

 method is 

2

𝔽

.

Given zero or more arguments, calls 

ToNumber

 on each of the arguments and returns the smallest of the resulting

values.

When the 

Math.min

Math.min

 method is called with zero or more arguments which form the rest parameter ...

args

, the

following steps are taken:

The comparison of values to determine the largest value is done using the 

Abstract Relational

Comparison

 algorithm except that 

+0

𝔽

 is considered to be larger than 

-0

𝔽

.

21.3.2.23  Math.log2 ( 

x

 )

21.3.2.24  Math.max ( ...

args

 )

21.3.2.25  Math.min ( ...

args

 )

526

1.  Let 

coerced

 be a new empty 

List

.

2.  For each element 

arg

 of 

args

, do

a.  Let 

n

 be ? 

ToNumber

(

arg

).

b.  Append 

n

 to 

coerced

.

3.  Let 

lowest

 be 

+

𝔽

.

4.  For each element 

number

 of 

coerced

, do

a.  If 

number

 is 

NaN

, return 

NaN

.

b.  If 

number

 is 

-0

𝔽

 and 

lowest

 is 

+0

𝔽

, set 

lowest

 to 

-0

𝔽

.

c.  If 

number

 < 

lowest

, set 

lowest

 to 

number

.

5.  Return 

lowest

.

NOTE

The 

"length"

 property of the 

min

min

 method is 

2

𝔽

.

When the 

Math.pow

Math.pow

 method is called with arguments 

base

 and 

exponent

, the following steps are taken:

1.  Set 

base

 to ? 

ToNumber

(

base

).

2.  Set 

exponent

 to ? 

ToNumber

(

exponent

).

3.  Return ! Number::exponentiate(

base

exponent

).

Returns a 

Number value

 with positive sign, greater than or equal to 

+0

𝔽

 but strictly less than 

1

𝔽

, chosen randomly or

pseudo randomly with approximately uniform distribution over that range, using an 

implementation-defined

algorithm or strategy. This function takes no arguments.

Each 

Math.random

Math.random

 function created for distinct realms must produce a distinct sequence of values from successive

calls.

Returns the 

Number value

 that is closest to 

x

 and is integral. If two integral Numbers are equally close to 

x

, then the

result is the 

Number value

 that is closer to +

. If 

x

 is already integral, the result is 

x

.

When the 

Math.round

Math.round

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

+

𝔽

-

𝔽

, or 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

The comparison of values to determine the largest value is done using the 

Abstract Relational

Comparison

 algorithm except that 

+0

𝔽

 is considered to be larger than 

-0

𝔽

.

Math.round(3.5)

Math.round(3.5)

 returns 4, but 

Math.round(-3.5)

Math.round(-3.5)

 returns -3.

21.3.2.26  Math.pow ( 

base

exponent

 )

21.3.2.27  Math.random ( )

21.3.2.28  Math.round ( 

x

 )

527

NOTE 2

Returns the sign of 

x

, indicating whether 

x

 is positive, negative, or zero.

When the 

Math.sign

Math.sign

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

3.  If 

n

 < 

+0

𝔽

, return 

-1

𝔽

.

4.  Return 

1

𝔽

.

Returns the sine of 

x

. The argument is expressed in radians.

When the 

Math.sin

Math.sin

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

3.  If 

n

 is 

+

𝔽

 or 

n

 is 

-

𝔽

, return 

NaN

.

4.  Return an 

implementation-approximated

(

n

).

Returns the hyperbolic sine of 

x

.

When the 

Math.sinh

Math.sinh

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, return 

n

.

3.  Return an 

implementation-approximated

 value representing the result of the hyperbolic sine of 

(

n

).

NOTE

Returns the square root of 

x

.

When the 

Math.sqrt

Math.sqrt

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

The value of 

Math.round(x)

Math.round(x)

 is not always the same as the value of

Math.floor(x + 0.5)

Math.floor(x + 0.5)

. When 

xx

 is 

-0

𝔽

 or is less than 

+0

𝔽

 but greater than or equal to 

-0.5

𝔽

,

Math.round(x)

Math.round(x)

 returns 

-0

𝔽

, but 

Math.floor(x + 0.5)

Math.floor(x + 0.5)

 returns 

+0

𝔽

.

Math.round(x)

Math.round(x)

 may also differ from the value of 

Math.floor(x + 0.5)

Math.floor(x + 0.5)

because of

internal rounding when computing 

x + 0.5

x + 0.5

.

The value of 

Math.sinh(x)

Math.sinh(x)

 is the same as the value of

(Math.exp(x) - Math.exp(-x)) / 2

(Math.exp(x) - Math.exp(-x)) / 2

.

21.3.2.29  Math.sign ( 

x

 )

21.3.2.30  Math.sin ( 

x

 )

21.3.2.31  Math.sinh ( 

x

 )

21.3.2.32  Math.sqrt ( 

x

 )

528

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

, or 

n

 is 

+

𝔽

, return 

n

.

3.  If 

n

 < 

+0

𝔽

, return 

NaN

.

4.  Return an 

implementation-approximated

n

).

Returns the tangent of 

x

. The argument is expressed in radians.

When the 

Math.tan

Math.tan

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

3.  If 

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, return 

NaN

.

4.  Return an 

implementation-approximated

 value representing the result of the tangent of 

n

).

Returns the hyperbolic tangent of 

x

.

When the 

Math.tanh

Math.tanh

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

, or 

n

 is 

-0

𝔽

, return 

n

.

3.  If 

n

 is 

+

𝔽

, return 

1

𝔽

.

4.  If 

n

 is 

-

𝔽

, return 

-1

𝔽

.

5.  Return an 

implementation-approximated

n

).

NOTE

Returns the integral part of the number 

x

, removing any fractional digits. If 

x

 is already integral, the result is 

x

.

When the 

Math.trunc

Math.trunc

 method is called with argument 

x

, the following steps are taken:

1.  Let 

n

 be ? 

ToNumber

(

x

).

2.  If 

n

 is 

NaN

n

 is 

+0

𝔽

n

 is 

-0

𝔽

n

 is 

+

𝔽

, or 

n

 is 

-

𝔽

, 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

𝔽

.

The following functions are 

abstract operations

 that operate on time values (defined in 

21.4.1.1

). Note that, in every

The value of 

Math.tanh(x)

Math.tanh(x)

 is the same as the value of

(Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x))

(Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x))

.

21.3.2.33  Math.tan ( 

x

 )

21.3.2.34  Math.tanh ( 

x

 )

21.3.2.35  Math.trunc ( 

x

 )

21.4  Date Objects

21.4.1  Overview of Date Objects and Definitions of Abstract Operations

529

case, if any argument to one of these functions is 

NaN

, the result will be 

NaN

.

Time measurement in ECMAScript is analogous to time measurement in POSIX, in particular sharing definition in
terms of the proleptic Gregorian calendar, an epoch of midnight at the beginning of 1 January 1970 UTC, and an
accounting of every day as comprising exactly 86,400 seconds (each of which is 1000 milliseconds long).

An ECMAScript 

time value

 is a Number, either a finite 

integral Number

 representing an instant in time to millisecond

precision or 

NaN

 representing no specific instant. A time value that is a multiple of 24 

×

 60 

×

 60 

×

 1000 = 86,400,000

(i.e., is equal to 86,400,000 

×

 

d

 for some 

integer

 

d

) represents the instant at the start of the UTC day that follows the

epoch by 

d

 whole UTC days (preceding the epoch for negative 

d

). Every other finite time value 

t

 is defined relative to

the greatest preceding time value 

s

 that is such a multiple, and represents the instant that occurs within the same UTC

day as 

s

 but follows it by 

t

 

 

s

 milliseconds.

Time values do not account for UTC leap seconds—there are no time values representing instants within positive leap
seconds, and there are time values representing instants removed from the UTC timeline by negative leap seconds.
However, the definition of time values nonetheless yields piecewise alignment with UTC, with discontinuities only at
leap second boundaries and zero difference outside of leap seconds.

A Number can exactly represent all integers from -9,007,199,254,740,992 to 9,007,199,254,740,992 (

21.1.2.8

 and 

21.1.2.6

).

A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds. This
yields a supported time value range of exactly -100,000,000 days to 100,000,000 days relative to midnight at the
beginning of 1 January 1970 UTC.

The exact moment of midnight at the beginning of 1 January 1970 UTC is represented by the time value 

+0

𝔽

.

NOTE

A given 

time value

 

t

 belongs to day number

Day(

t

(

floor

t

 / 

msPerDay

)))

where the number of milliseconds per day is

msPerDay = 

86400000

𝔽

The remainder is called the time within the day:

TimeWithinDay(

t

) = 

t

modulo

msPerDay

))

ECMAScript uses a proleptic Gregorian calendar to map a day number to a year number and to determine the month

The 400 year cycle of the proleptic Gregorian calendar contains 97 leap years. This yields an
average of 365.2425 days per year, which is 31,556,952,000 milliseconds. Therefore, the maximum
range a Number could represent exactly with millisecond precision is approximately -285,426 to
285,426 years relative to 1970. The smaller range supported by a time value as specified in this
section is approximately -273,790 to 273,790 years relative to 1970.

21.4.1.1  Time Values and Time Range

21.4.1.2  Day Number and Time within Day

21.4.1.3  Year Number

530

and date within that year. In this calendar, leap years are precisely those which are (divisible by 4) and ((not divisible
by 100) or (divisible by 400)). The number of days in year number 

y

 is therefore defined by

DaysInYear(

y

)

365

𝔽

(

y

modulo

 4) 

 0

366

𝔽

(

y

modulo

 4) = 0 and (

y

modulo

 100) 

 0

365

𝔽

(

y

modulo

 100) = 0 and (

(

y

modulo

 400) 

 0

366

𝔽

(

y

modulo

 400) = 0

All non-leap years have 365 days with the usual number of days per month and leap years have an extra day in
February. The day number of the first day of year 

y

 is given by:

DayFromYear(

y

) = 

(365 

×

y

) - 1970) + 

floor

((

(

y

) - 1969) / 4) - 

floor

((

(

y

) - 1901) / 100) + 

floor

((

(

y

) - 1601) /

400))

The 

time value

 of the start of a year is:

TimeFromYear(

y

) = 

msPerDay

 

×

 

DayFromYear

(

y

)

time value

 determines a year by:

YearFromTime(

t

) = the largest 

integral Number

 

y

 (closest to +

) such that 

TimeFromYear

(

y

 

t

The leap-year function is 

1

𝔽

 for a time within a leap year and otherwise is 

+0

𝔽

:

InLeapYear(

t

)

+0

𝔽

 if 

DaysInYear

(

YearFromTime

(

t

)) = 

365

𝔽

1

𝔽

 if 

DaysInYear

(

YearFromTime

(

t

)) = 

366

𝔽

Months are identified by an 

integral Number

 in the range 

+0

𝔽

 to 

11

𝔽

, inclusive. The mapping 

MonthFromTime

(

t

) from

time value

 

t

 to a month number is defined by:

MonthFromTime(

t

)

+0

𝔽

 if 

+0

𝔽

 

 

DayWithinYear

(

t

) < 

31

𝔽

1

𝔽

 if 

31

𝔽

 

 

DayWithinYear

(

t

) < 

59

𝔽

 + 

InLeapYear

(

t

)

2

𝔽

 if 

59

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

90

𝔽

 + 

InLeapYear

(

t

)

3

𝔽

 if 

90

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

120

𝔽

 + 

InLeapYear

(

t

)

4

𝔽

 if 

120

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

151

𝔽

 + 

InLeapYear

(

t

)

5

𝔽

 if 

151

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

181

𝔽

 + 

InLeapYear

(

t

)

6

𝔽

 if 

181

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

212

𝔽

 + 

InLeapYear

(

t

)

7

𝔽

 if 

212

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

243

𝔽

 + 

InLeapYear

(

t

)

8

𝔽

 if 

243

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

273

𝔽

 + 

InLeapYear

(

t

)

9

𝔽

 if 

273

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

304

𝔽

 + 

InLeapYear

(

t

)

10

𝔽

 if 

304

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

334

𝔽

 + 

InLeapYear

(

t

)

11

𝔽

 if 

334

𝔽

 + 

InLeapYear

(

t

 

DayWithinYear

(

t

) < 

365

𝔽

 + 

InLeapYear

(

t

)

where

21.4.1.4  Month Number

531

DayWithinYear(

t

) = 

Day

(

t

) - 

DayFromYear

(

YearFromTime

(

t

))

A month value of 

+0

𝔽

 specifies January; 

1

𝔽

 specifies February; 

2

𝔽

 specifies March; 

3

𝔽

 specifies April; 

4

𝔽

 specifies May;

5

𝔽

 specifies June; 

6

𝔽

 specifies July; 

7

𝔽

 specifies August; 

8

𝔽

 specifies September; 

9

𝔽

 specifies October; 

10

𝔽

 specifies

November; and 

11

𝔽

 specifies December. Note that 

MonthFromTime

(

+0

𝔽

) = 

+0

𝔽

, corresponding to Thursday, 1 January

1970.

A date number is identified by an 

integral Number

 in the range 

1

𝔽

 through 

31

𝔽

, inclusive. The mapping

DateFromTime(

t

) from a 

time value

 

t

 to a date number is defined by:

DateFromTime(

t

)

DayWithinYear

(

t

) + 

1

𝔽

 if 

MonthFromTime

(

t

) = 

+0

𝔽

DayWithinYear

(

t

) - 

30

𝔽

 if 

MonthFromTime

(

t

) = 

1

𝔽

DayWithinYear

(

t

) - 

58

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

2

𝔽

DayWithinYear

(

t

) - 

89

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

3

𝔽

DayWithinYear

(

t

) - 

119

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

4

𝔽

DayWithinYear

(

t

) - 

150

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

5

𝔽

DayWithinYear

(

t

) - 

180

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

6

𝔽

DayWithinYear

(

t

) - 

211

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

7

𝔽

DayWithinYear

(

t

) - 

242

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

8

𝔽

DayWithinYear

(

t

) - 

272

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

9

𝔽

DayWithinYear

(

t

) - 

303

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

10

𝔽

DayWithinYear

(

t

) - 

333

𝔽

 - 

InLeapYear

(

t

) if 

MonthFromTime

(

t

) = 

11

𝔽

The weekday for a particular 

time value

 

t

 is defined as

WeekDay(

t

) = 

Day

(

t

) + 

4

𝔽

modulo

 7)

A weekday value of 

+0

𝔽

 specifies Sunday; 

1

𝔽

 specifies Monday; 

2

𝔽

 specifies Tuesday; 

3

𝔽

 specifies Wednesday; 

4

𝔽

specifies Thursday; 

5

𝔽

 specifies Friday; and 

6

𝔽

 specifies Saturday. Note that WeekDay(

+0

𝔽

) = 

4

𝔽

, corresponding to

Thursday, 1 January 1970.

LocalTZA( 

t

isUTC

 ) is an 

implementation-defined

 algorithm that returns an 

integral Number

 representing the local

time zone adjustment, or offset, in milliseconds. The local political rules for standard time and daylight saving time in
effect at 

t

 should be used to determine the result in the way specified in this section.

When 

isUTC

 is true, LocalTZA( 

t

UTC

, true ) should return the offset of the local time zone from UTC measured in

milliseconds at time represented by 

time value

 

t

UTC

. When the result is added to 

t

UTC

, it should yield the

corresponding Number 

t

local

.

When 

isUTC

 is false, LocalTZA( 

t

local

, false ) should return the offset of the local time zone from UTC measured in

21.4.1.5  Date Number

21.4.1.6  Week Day

21.4.1.7  LocalTZA ( 

t

isUTC

 )

532

milliseconds at local time represented by Number 

t

local

. When the result is subtracted from 

t

local

, it should yield the

corresponding 

time value

 

t

UTC

.

Input 

t

 is nominally a 

time value

 but may be any 

Number value

. This can occur when 

isUTC

 is false and 

t

local

represents a 

time value

 that is already offset outside of the 

time value

 range at the range boundaries. The algorithm

must not limit 

t

local

 to the 

time value

 range, so that such inputs are supported.

When 

t

local

 represents local time repeating multiple times at a negative time zone transition (e.g. when the daylight

saving time ends or the time zone offset is decreased due to a time zone rule change) or skipped local time at a
positive time zone transitions (e.g. when the daylight saving time starts or the time zone offset is increased due to a
time zone rule change), 

t

local

 must be interpreted using the time zone offset before the transition.

If an implementation does not support a conversion described above or if political rules for time 

t

 are not available

within the implementation, the result must be 

+0

𝔽

.

NOTE

The abstract operation LocalTime takes argument 

t

. It converts 

t

 from UTC to local time. It performs the following

steps when called:

1.  Return 

t

 + 

LocalTZA

(

t

true

).

NOTE

The abstract operation UTC takes argument 

t

. It converts 

t

 from local time to UTC. It performs the following steps

when called:

It is recommended that implementations use the time zone information of the IANA Time Zone
Database 

https://www.iana.org/time-zones/

.

1:30 AM on 5 November 2017 in America/New_York is repeated twice (fall backward), but it
must be interpreted as 1:30 AM UTC-04 instead of 1:30 AM UTC-05.
LocalTZA(

TimeClip

(

MakeDate

(

MakeDay

(2017, 10, 5), 

MakeTime

(1, 30, 0, 0))), false) is -4 

×

msPerHour

.

2:30 AM on 12 March 2017 in America/New_York does not exist, but it must be interpreted as
2:30 AM UTC-05 (equivalent to 3:30 AM UTC-04).
LocalTZA(

TimeClip

(

MakeDate

(

MakeDay

(2017, 2, 12), 

MakeTime

(2, 30, 0, 0))), false) is -5 

×

msPerHour

.

Local time zone offset values may be positive 

or

 negative.

Two different input time values 

t

UTC

 are converted to the same local time t

local

 at a negative time

zone transition when there are repeated times (e.g. the daylight saving time ends or the time
zone adjustment is decreased.).

LocalTime(

UTC

(

t

local

)) is not necessarily always equal to 

t

local

. Correspondingly,

UTC

(LocalTime(

t

UTC

)) is not necessarily always equal to 

t

UTC

.

21.4.1.8  LocalTime ( 

t

 )

21.4.1.9  UTC ( 

t

 )

533

1.  Return 

t

 - 

LocalTZA

(

t

false

).

NOTE

The following 

abstract operations

 are useful in decomposing time values:

HourFromTime(

t

) = 

(

floor

t

 / 

msPerHour

)) 

modulo

 

HoursPerDay

)

MinFromTime(

t

floor

(

(

t

 / 

msPerMinute

)) 

modulo

 

MinutesPerHour

)

SecFromTime(

t

floor

(

(

t

 / 

msPerSecond

)) 

modulo

 

SecondsPerMinute

)

msFromTime(

t

(

t

modulo

 

msPerSecond

)

where

HoursPerDay = 24
MinutesPerHour = 60
SecondsPerMinute = 60
msPerSecond = 

1000

𝔽

msPerMinute = 

60000

𝔽

 = 

msPerSecond

 

×

 

SecondsPerMinute

)

msPerHour = 

3600000

𝔽

 = 

msPerMinute

 

×

 

MinutesPerHour

)

The abstract operation MakeTime takes arguments 

hour

 (a Number), 

min

 (a Number), 

sec

 (a Number), and 

ms

 (a

Number). It calculates a number of milliseconds. It performs the following steps when called:

1.  If 

hour

 is not finite or 

min

 is not finite or 

sec

 is not finite or 

ms

 is not finite, return 

NaN

.

2.  Let 

h

 be 

(! 

ToIntegerOrInfinity

(

hour

)).

3.  Let 

m

(! 

ToIntegerOrInfinity

(

min

)).

4.  Let 

s

 be 

(! 

ToIntegerOrInfinity

(

sec

)).

5.  Let 

milli

ToIntegerOrInfinity

(

ms

)).

6.  Let 

t

 be ((

h

 

**

 

msPerHour

 

++

 

m

 

**

 

msPerMinute

++

 

s

 

**

 

msPerSecond

++

 

milli

, performing the arithmetic according

to 

IEEE 754-2019

 rules (that is, as if using the ECMAScript operators 

**

 and 

++

).

7.  Return 

t

.

The abstract operation MakeDay takes arguments 

year

 (a Number), 

month

 (a Number), and 

date

 (a Number). It

calculates a number of days. It performs the following steps when called:

1.  If 

year

 is not finite or 

month

 is not finite or 

date

 is not finite, return 

NaN

.

2.  Let 

y

 be 

(! 

ToIntegerOrInfinity

(

year

)).

3.  Let 

m

(! 

ToIntegerOrInfinity

(

month

)).

4.  Let 

dt

 be 

(! 

ToIntegerOrInfinity

(

date

)).

5.  Let 

ym

 be 

y

 + 

(

floor

m

) / 12)).

6.  If 

ym

 is not finite, return 

NaN

.

UTC(

LocalTime

(

t

UTC

)) is not necessarily always equal to 

t

UTC

. Correspondingly,

LocalTime

(UTC(

t

local

)) is not necessarily always equal to 

t

local

.

21.4.1.10  Hours, Minutes, Second, and Milliseconds

21.4.1.11  MakeTime ( 

hour

min

sec

ms

 )

21.4.1.12  MakeDay ( 

year

month

date

 )

534

7.  Let 

mn

 be 

m

modulo

 12).

8.  Find a finite 

time value

 

t

 such that 

YearFromTime

(

t

) is 

ym

 and 

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

𝔽

.

The abstract operation MakeDate takes arguments 

day

 (a Number) and 

time

 (a Number). It calculates a number of

milliseconds. 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

.

The abstract operation TimeClip takes argument 

time

 (a Number). It calculates a number of milliseconds. It performs

the following steps when called:

1.  If 

time

 is not finite, return 

NaN

.

2.  If 

abs

(

time

)) > 8.64 

×

 10

15

, return 

NaN

.

3.  Return 

ToIntegerOrInfinity

(

time

)).

ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 calendar
date extended format. The format is as follows: 

YYYY-MM-DDTHH:mm:ss.sssZ

YYYY-MM-DDTHH:mm:ss.sssZ

Where the elements are as follows:

YYYY

YYYY

is the year in the proleptic Gregorian calendar as four decimal digits from 0000 to 9999, or as an

expanded year

 of 

"+"

 or 

"-"

 followed by six decimal digits.

--

"-"

 (hyphen) appears literally twice in the string.

MM

MM

is the month of the year as two decimal digits from 01 (January) to 12 (December).

DD

DD

is the day of the month as two decimal digits from 01 to 31.

TT

"T"

 appears literally in the string, to indicate the beginning of the time element.

HH

HH

is the number of complete hours that have passed since midnight as two decimal digits from 00 to 24.

::

":"

 (colon) appears literally twice in the string.

mm

mm

is the number of complete minutes since the start of the hour as two decimal digits from 00 to 59.

ss

ss

is the number of complete seconds since the start of the minute as two decimal digits from 00 to 59.

..

"."

 (dot) appears literally in the string.

sss

sss

is the number of complete milliseconds since the start of the second as three decimal digits.

ZZ

is the UTC offset representation specified as 

"Z"

 (for UTC with no offset) or an offset of either 

"+"

 or 

"-"

followed by a time expression 

HH:mm

HH:mm

 (indicating local time ahead of or behind UTC, respectively)

This format includes date-only forms:

21.4.1.13  MakeDate ( 

day

time

 )

21.4.1.14  TimeClip ( 

time

 )

21.4.1.15  Date Time String Format

535

YYYY
YYYY-MM
YYYY-MM-DD
        

It also includes “date-time” forms that consist of one of the above date-only forms immediately followed by one of the
following time forms with an optional UTC offset representation appended:

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

A string containing out-of-bounds or nonconforming elements is not a valid instance of this format.

NOTE 1

NOTE 2

Covering

 the full 

time value

 range of approximately 273,790 years forward or backward from 1 January 1970 (

21.4.1.1

)

requires representing years before 0 or after 9999. ISO 8601 permits expansion of the year representation, but only by
mutual agreement of the partners in information interchange. In the simplified ECMAScript format, such an
expanded year representation shall have 6 digits and is always prefixed with a + or - sign. The year 0 is considered
positive and hence prefixed with a + sign. Strings matching the 

Date Time String Format

 with expanded years

representing instants in time outside the range of a 

time value

 are treated as unrecognizable by 

Date.parse

Date.parse

 and

cause that function to return 

NaN

 without falling back to implementation-specific behaviour or heuristics.

NOTE

As every day both starts and ends with midnight, the two notations 

00:00

00:00

 and 

24:00

24:00

 are

available to distinguish the two midnights that can be associated with one date. This means that
the following two notations refer to exactly the same point in time: 

1995-02-04T24:00

1995-02-04T24:00

 and

1995-02-05T00:00

1995-02-05T00:00

. This interpretation of the latter form as "end of a calendar day" is

consistent with ISO 8601, even though that specification reserves it for describing time intervals
and does not permit it within representations of single points in time.

There exists no international standard that specifies abbreviations for civil time zones like CET,
EST, etc. and sometimes the same abbreviation is even used for two very different time zones. For
this reason, both ISO 8601 and this format specify numeric representations of time zone offsets.

Examples of date-time values with expanded years:

-271821-04-20T00:00:00Z

271822 B.C.

-000001-01-01T00:00:00Z

2 B.C.

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

21.4.1.15.1  Expanded Years

536

The Date 

constructor

:

is 

%Date%

.

is the initial value of the 

"Date"

 property of the 

global object

.

creates and initializes a new Date object when called as a 

constructor

.

returns a String representing the current time (UTC) when called as a function rather than as a 

constructor

.

is a function whose behaviour differs based upon the number and types of its arguments.
is designed to be subclassable. It may be used as the value of an 

extends

extends

 clause of a class definition. Subclass

constructors that intend to inherit the specified Date behaviour must include a 

super

super

 call to the Date

constructor

 to create and initialize the subclass instance with a [[DateValue]] internal slot.

has a 

"length"

 property whose value is 

7

𝔽

.

When the 

Date

Date

 function is called, the following steps are taken:

1.  If NewTarget is 

undefined

, then

a.  Let 

now

 be the 

time value

 (UTC) identifying the current time.

b.  Return 

ToDateString

(

now

).

2.  Let 

numberOfArgs

 be the number of elements in 

values

.

3.  If 

numberOfArgs

 = 0, then

a.  Let 

dv

 be the 

time value

 (UTC) identifying the current time.

4.  Else if 

numberOfArgs

 = 1, then

a.  Let 

value

 be 

values

[0].

b.  If 

Type

(

value

) is Object and 

value

 has a [[DateValue]] internal slot, then

i.  Let 

tv

 be ! 

thisTimeValue

(

value

).

c.  Else,

i.  Let 

v

 be ? 

ToPrimitive

(

value

).

ii.  If 

Type

(

v

) is String, then

1. 

Assert

: The next step never returns an 

abrupt completion

 because 

Type

(

v

) is String.

2.  Let 

tv

 be the result of parsing 

v

 as a date, in exactly the same manner as for the 

parse

parse

method (

21.4.3.2

).

iii.  Else,

1.  Let 

tv

 be ? 

ToNumber

(

v

).

d.  Let 

dv

 be 

TimeClip

(

tv

).

5.  Else,

a. 

Assert

numberOfArgs

 

 2.

b.  Let 

y

 be ? 

ToNumber

(

values

[0]).

c.  Let 

m

 be ? 

ToNumber

(

values

[1]).

d.  If 

numberOfArgs

 > 2, let 

dt

 be ? 

ToNumber

(

values

[2]); else let 

dt

 be 

1

𝔽

.

e.  If 

numberOfArgs

 > 3, let 

h

 be ? 

ToNumber

(

values

[3]); else let 

h

 be 

+0

𝔽

.

f.  If 

numberOfArgs

 > 4, let 

min

 be ? 

ToNumber

(

values

[4]); else let 

min

 be 

+0

𝔽

.

g.  If 

numberOfArgs

 > 5, let 

s

 be ? 

ToNumber

(

values

[5]); else let 

s

 be 

+0

𝔽

.

h.  If 

numberOfArgs

 > 6, let 

milli

 be ? 

ToNumber

(

values

[6]); else let 

milli

 be 

+0

𝔽

.

i.  If 

y

 is 

NaN

, let 

yr

 be 

NaN

.

j.  Else,

21.4.2  The Date Constructor

21.4.2.1  Date ( ...

values

 )

537

i.  Let 

yi

 be ! 

ToIntegerOrInfinity

(

y

).

ii.  If 0 

 

yi

 

 99, let 

yr

 be 

1900

𝔽

 + 

(

yi

); otherwise, let 

yr

 be 

y

.

k.  Let 

finalDate

 be 

MakeDate

(

MakeDay

(

yr

m

dt

), 

MakeTime

(

h

min

s

milli

)).

l.  Let 

dv

 be 

TimeClip

(

UTC

(

finalDate

)).

6.  Let 

O

 be ? 

OrdinaryCreateFromConstructor

(NewTarget, 

"%Date.prototype%"

, « [[DateValue]] »).

7.  Set 

O

.[[DateValue]] to 

dv

.

8.  Return 

O

.

The Date 

constructor

:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has the following properties:

The 

now

now

 function returns the 

time value

 designating the UTC date and time of the occurrence of the call to 

now

now

.

The 

parse

parse

 function applies the 

ToString

 operator to its argument. If 

ToString

 results in an 

abrupt completion

 the

Completion Record

 is immediately returned. Otherwise, 

parse

parse

 interprets the resulting String as a date and time; it

returns a Number, the UTC 

time value

 corresponding to the date and time. The String may be interpreted as a local

time, a UTC time, or a time in some other time zone, depending on the contents of the String. The function first
attempts to parse the String according to the format described in Date Time String Format (

21.4.1.15

), including

expanded years. If the String does not conform to that format the function may fall back to any implementation-
specific heuristics or implementation-specific date formats. Strings that are unrecognizable or contain out-of-bounds
format element values shall cause 

Date.parse

Date.parse

 to return 

NaN

.

If the String conforms to the 

Date Time String Format

, substitute values take the place of absent format elements.

When the 

MM

MM

 or 

DD

DD

 elements are absent, 

"01"

 is used. When the 

HH

HH

mm

mm

, or 

ss

ss

 elements are absent, 

"00"

 is used. When

the 

sss

sss

 element is absent, 

"000"

 is used. When the UTC offset representation is absent, date-only forms are

interpreted as a UTC time and date-time forms are interpreted as a local time.

If 

xx

 is any Date object whose milliseconds amount is zero within a particular implementation of ECMAScript, then all

of the following expressions should produce the same numeric value in that implementation, if all the properties
referenced have their initial values:

However, the expression

is not required to produce the same 

Number value

 as the preceding three expressions and, in general, the value

produced by 

Date.parse

Date.parse

 is 

implementation-defined

 when given any String value that does not conform to the

x.valueOf()

Date

.parse(x.toString())

Date

.parse(x.toUTCString())

Date

.parse(x.toISOString())

Date

.parse(x.toLocaleString())

21.4.3  Properties of the Date Constructor

21.4.3.1  Date.now ( )

21.4.3.2  Date.parse ( 

string

 )

538

Date Time String Format (

21.4.1.15

) and that could not be produced in that implementation by the 

toString

toString

 or

toUTCString

toUTCString

 method.

The initial value of 

Date.prototype

Date.prototype

 is the 

Date prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

When the 

UTC

UTC

 function is called, the following steps are taken:

1.  Let 

y

 be ? 

ToNumber

(

year

).

2.  If 

month

 is present, let 

m

 be ? 

ToNumber

(

month

); else let 

m

 be 

+0

𝔽

.

3.  If 

date

 is present, let 

dt

 be ? 

ToNumber

(

date

); else let 

dt

 be 

1

𝔽

.

4.  If 

hours

 is present, let 

h

 be ? 

ToNumber

(

hours

); else let 

h

 be 

+0

𝔽

.

5.  If 

minutes

 is present, let 

min

 be ? 

ToNumber

(

minutes

); else let 

min

 be 

+0

𝔽

.

6.  If 

seconds

 is present, let 

s

 be ? 

ToNumber

(

seconds

); else let 

s

 be 

+0

𝔽

.

7.  If 

ms

 is present, let 

milli

 be ? 

ToNumber

(

ms

); else let 

milli

 be 

+0

𝔽

.

8.  If 

y

 is 

NaN

, let 

yr

 be 

NaN

.

9.  Else,

a.  Let 

yi

 be ! 

ToIntegerOrInfinity

(

y

).

b.  If 0 

 

yi

 

 99, let 

yr

 be 

1900

𝔽

 + 

(

yi

); otherwise, let 

yr

 be 

y

.

10.  Return 

TimeClip

(

MakeDate

(

MakeDay

(

yr

m

dt

), 

MakeTime

(

h

min

s

milli

))).

The 

"length"

 property of the 

UTC

UTC

 function is 

7

𝔽

.

NOTE

The 

Date prototype object

:

is 

%Date.prototype%

.

is itself an 

ordinary object

.

is not a Date instance and does not have a [[DateValue]] internal slot.
has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

Unless explicitly defined otherwise, the methods of the Date prototype object defined below are not generic and the

this

 value passed to them must be an object that has a [[DateValue]] internal slot that has been initialized to a 

time

value

.

The abstract operation 

thisTimeValue

 takes argument 

value

. It performs the following steps when called:

1.  If 

Type

(

value

) is Object and 

value

 has a [[DateValue]] internal slot, then

The 

UTC

UTC

 function differs from the Date 

constructor

 in two ways: it returns a 

time value

 as a

Number, rather than creating a Date object, and it interprets the arguments in UTC rather than as
local time.

21.4.3.3  Date.prototype

21.4.3.4  Date.UTC ( 

year

 [ , 

month

 [ , 

date

 [ , 

hours

 [ , 

minutes

 [ , 

seconds

 [ , 

ms

 ] ] ] ] ] ] )

21.4.4  Properties of the Date Prototype Object

539

a.  Return 

value

.[[DateValue]].

2.  Throw a 

TypeError

 exception.

In following descriptions of functions that are properties of the Date prototype object, the phrase “

this Date object

refers to the object that is the 

this

 value for the invocation of the function. If the Type of the 

this

 value is not Object, a

TypeError

 exception is thrown. The phrase “

this time value

” within the specification of a method refers to the result

returned by calling the abstract operation 

thisTimeValue

 with the 

this

 value of the method invocation passed as the

argument.

The initial value of 

Date.prototype.constructor

Date.prototype.constructor

 is 

%Date%

.

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

DateFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

WeekDay

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

YearFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

HourFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

21.4.4.1  Date.prototype.constructor

21.4.4.2  Date.prototype.getDate ( )

21.4.4.3  Date.prototype.getDay ( )

21.4.4.4  Date.prototype.getFullYear ( )

21.4.4.5  Date.prototype.getHours ( )

21.4.4.6  Date.prototype.getMilliseconds ( )

540

 

 

 

 

 

 

 

Content      ..     47      48      49      50     ..