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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     48      49      50      51     ..

 

 

 

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

 

 

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

msFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

MinFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

MonthFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

SecFromTime

(

LocalTime

(

t

)).

The following steps are performed:

1.  Return ? 

thisTimeValue

(

this

 value).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return (

t

 - 

LocalTime

(

t

)) / 

msPerMinute

.

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

DateFromTime

(

t

).

21.4.4.7  Date.prototype.getMinutes ( )

21.4.4.8  Date.prototype.getMonth ( )

21.4.4.9  Date.prototype.getSeconds ( )

21.4.4.10  Date.prototype.getTime ( )

21.4.4.11  Date.prototype.getTimezoneOffset ( )

21.4.4.12  Date.prototype.getUTCDate ( )

21.4.4.13  Date.prototype.getUTCDay ( )

541

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

WeekDay

(

t

).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

YearFromTime

(

t

).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

HourFromTime

(

t

).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

msFromTime

(

t

).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

MinFromTime

(

t

).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

MonthFromTime

(

t

).

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

21.4.4.14  Date.prototype.getUTCFullYear ( )

21.4.4.15  Date.prototype.getUTCHours ( )

21.4.4.16  Date.prototype.getUTCMilliseconds ( )

21.4.4.17  Date.prototype.getUTCMinutes ( )

21.4.4.18  Date.prototype.getUTCMonth ( )

21.4.4.19  Date.prototype.getUTCSeconds ( )

542

2.  If 

t

 is 

NaN

, return 

NaN

.

3.  Return 

SecFromTime

(

t

).

The following steps are performed:

1.  Let 

t

 be 

LocalTime

(? 

thisTimeValue

(

this

 value)).

2.  Let 

dt

 be ? 

ToNumber

(

date

).

3.  Let 

newDate

 be 

MakeDate

(

MakeDay

(

YearFromTime

(

t

), 

MonthFromTime

(

t

), 

dt

), 

TimeWithinDay

(

t

)).

4.  Let 

u

 be 

TimeClip

(

UTC

(

newDate

)).

5.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

6.  Return 

u

.

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, set 

t

 to 

+0

𝔽

; otherwise, set 

t

 to 

LocalTime

(

t

).

3.  Let 

y

 be ? 

ToNumber

(

year

).

4.  If 

month

 is not present, let 

m

 be 

MonthFromTime

(

t

); otherwise, let 

m

 be ? 

ToNumber

(

month

).

5.  If 

date

 is not present, let 

dt

 be 

DateFromTime

(

t

); otherwise, let 

dt

 be ? 

ToNumber

(

date

).

6.  Let 

newDate

 be 

MakeDate

(

MakeDay

(

y

m

dt

), 

TimeWithinDay

(

t

)).

7.  Let 

u

 be 

TimeClip

(

UTC

(

newDate

)).

8.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

9.  Return 

u

.

The 

"length"

 property of the 

setFullYear

setFullYear

 method is 

3

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be 

LocalTime

(? 

thisTimeValue

(

this

 value)).

2.  Let 

h

 be ? 

ToNumber

(

hour

).

3.  If 

min

 is not present, let 

m

 be 

MinFromTime

(

t

); otherwise, let 

m

 be ? 

ToNumber

(

min

).

4.  If 

sec

 is not present, let 

s

 be 

SecFromTime

(

t

); otherwise, let 

s

 be ? 

ToNumber

(

sec

).

5.  If 

ms

 is not present, let 

milli

 be 

msFromTime

(

t

); otherwise, let 

milli

 be ? 

ToNumber

(

ms

).

6.  Let 

date

 be 

MakeDate

(

Day

(

t

), 

MakeTime

(

h

m

s

milli

)).

7.  Let 

u

 be 

TimeClip

(

UTC

(

date

)).

8.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

9.  Return 

u

.

If 

month

 is not present, this method behaves as if 

month

 was present with the value

getMonth()

getMonth()

. If 

date

 is not present, it behaves as if 

date

 was present with the value

getDate()

getDate()

.

21.4.4.20  Date.prototype.setDate ( 

date

 )

21.4.4.21  Date.prototype.setFullYear ( 

year

 [ , 

month

 [ , 

date

 ] ] )

21.4.4.22  Date.prototype.setHours ( 

hour

 [ , 

min

 [ , 

sec

 [ , 

ms

 ] ] ] )

543

The 

"length"

 property of the 

setHours

setHours

 method is 

4

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be 

LocalTime

(? 

thisTimeValue

(

this

 value)).

2.  Set 

ms

 to ? 

ToNumber

(

ms

).

3.  Let 

time

 be 

MakeTime

(

HourFromTime

(

t

), 

MinFromTime

(

t

), 

SecFromTime

(

t

), 

ms

).

4.  Let 

u

 be 

TimeClip

(

UTC

(

MakeDate

(

Day

(

t

), 

time

))).

5.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

6.  Return 

u

.

The following steps are performed:

1.  Let 

t

 be 

LocalTime

(? 

thisTimeValue

(

this

 value)).

2.  Let 

m

 be ? 

ToNumber

(

min

).

3.  If 

sec

 is not present, let 

s

 be 

SecFromTime

(

t

); otherwise, let 

s

 be ? 

ToNumber

(

sec

).

4.  If 

ms

 is not present, let 

milli

 be 

msFromTime

(

t

); otherwise, let 

milli

 be ? 

ToNumber

(

ms

).

5.  Let 

date

 be 

MakeDate

(

Day

(

t

), 

MakeTime

(

HourFromTime

(

t

), 

m

s

milli

)).

6.  Let 

u

 be 

TimeClip

(

UTC

(

date

)).

7.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

8.  Return 

u

.

The 

"length"

 property of the 

setMinutes

setMinutes

 method is 

3

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be 

LocalTime

(? 

thisTimeValue

(

this

 value)).

2.  Let 

m

 be ? 

ToNumber

(

month

).

3.  If 

date

 is not present, let 

dt

 be 

DateFromTime

(

t

); otherwise, let 

dt

 be ? 

ToNumber

(

date

).

4.  Let 

newDate

 be 

MakeDate

(

MakeDay

(

YearFromTime

(

t

), 

m

dt

), 

TimeWithinDay

(

t

)).

5.  Let 

u

 be 

TimeClip

(

UTC

(

newDate

)).

6.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

7.  Return 

u

.

If 

min

 is not present, this method behaves as if 

min

 was present with the value 

getMinutes()

getMinutes()

.

If 

sec

 is not present, it behaves as if 

sec

 was present with the value 

getSeconds()

getSeconds()

. If 

ms

 is not

present, it behaves as if 

ms

 was present with the value 

getMilliseconds()

getMilliseconds()

.

If 

sec

 is not present, this method behaves as if 

sec

 was present with the value 

getSeconds()

getSeconds()

.

If 

ms

 is not present, this behaves as if 

ms

 was present with the value 

getMilliseconds()

getMilliseconds()

.

21.4.4.23  Date.prototype.setMilliseconds ( 

ms

 )

21.4.4.24  Date.prototype.setMinutes ( 

min

 [ , 

sec

 [ , 

ms

 ] ] )

21.4.4.25  Date.prototype.setMonth ( 

month

 [ , 

date

 ] )

544

The 

"length"

 property of the 

setMonth

setMonth

 method is 

2

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be 

LocalTime

(? 

thisTimeValue

(

this

 value)).

2.  Let 

s

 be ? 

ToNumber

(

sec

).

3.  If 

ms

 is not present, let 

milli

 be 

msFromTime

(

t

); otherwise, let 

milli

 be ? 

ToNumber

(

ms

).

4.  Let 

date

 be 

MakeDate

(

Day

(

t

), 

MakeTime

(

HourFromTime

(

t

), 

MinFromTime

(

t

), 

s

milli

)).

5.  Let 

u

 be 

TimeClip

(

UTC

(

date

)).

6.  Set the [[DateValue]] internal slot of 

this Date object

 to 

u

.

7.  Return 

u

.

The 

"length"

 property of the 

setSeconds

setSeconds

 method is 

2

𝔽

.

NOTE

The following steps are performed:

1.  Perform ? 

thisTimeValue

(

this

 value).

2.  Let 

t

 be ? 

ToNumber

(

time

).

3.  Let 

v

 be 

TimeClip

(

t

).

4.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

5.  Return 

v

.

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  Let 

dt

 be ? 

ToNumber

(

date

).

3.  Let 

newDate

 be 

MakeDate

(

MakeDay

(

YearFromTime

(

t

), 

MonthFromTime

(

t

), 

dt

), 

TimeWithinDay

(

t

)).

4.  Let 

v

 be 

TimeClip

(

newDate

).

5.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

6.  Return 

v

.

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  If 

t

 is 

NaN

, set 

t

 to 

+0

𝔽

.

If 

date

 is not present, this method behaves as if 

date

 was present with the value 

getDate()

getDate()

.

If 

ms

 is not present, this method behaves as if 

ms

 was present with the value

getMilliseconds()

getMilliseconds()

.

21.4.4.26  Date.prototype.setSeconds ( 

sec

 [ , 

ms

 ] )

21.4.4.27  Date.prototype.setTime ( 

time

 )

21.4.4.28  Date.prototype.setUTCDate ( 

date

 )

21.4.4.29  Date.prototype.setUTCFullYear ( 

year

 [ , 

month

 [ , 

date

 ] ] )

545

3.  Let 

y

 be ? 

ToNumber

(

year

).

4.  If 

month

 is not present, let 

m

 be 

MonthFromTime

(

t

); otherwise, let 

m

 be ? 

ToNumber

(

month

).

5.  If 

date

 is not present, let 

dt

 be 

DateFromTime

(

t

); otherwise, let 

dt

 be ? 

ToNumber

(

date

).

6.  Let 

newDate

 be 

MakeDate

(

MakeDay

(

y

m

dt

), 

TimeWithinDay

(

t

)).

7.  Let 

v

 be 

TimeClip

(

newDate

).

8.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

9.  Return 

v

.

The 

"length"

 property of the 

setUTCFullYear

setUTCFullYear

 method is 

3

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  Let 

h

 be ? 

ToNumber

(

hour

).

3.  If 

min

 is not present, let 

m

 be 

MinFromTime

(

t

); otherwise, let 

m

 be ? 

ToNumber

(

min

).

4.  If 

sec

 is not present, let 

s

 be 

SecFromTime

(

t

); otherwise, let 

s

 be ? 

ToNumber

(

sec

).

5.  If 

ms

 is not present, let 

milli

 be 

msFromTime

(

t

); otherwise, let 

milli

 be ? 

ToNumber

(

ms

).

6.  Let 

newDate

 be 

MakeDate

(

Day

(

t

), 

MakeTime

(

h

m

s

milli

)).

7.  Let 

v

 be 

TimeClip

(

newDate

).

8.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

9.  Return 

v

.

The 

"length"

 property of the 

setUTCHours

setUTCHours

 method is 

4

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  Let 

milli

 be ? 

ToNumber

(

ms

).

3.  Let 

time

 be 

MakeTime

(

HourFromTime

(

t

), 

MinFromTime

(

t

), 

SecFromTime

(

t

), 

milli

).

4.  Let 

v

 be 

TimeClip

(

MakeDate

(

Day

(

t

), 

time

)).

5.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

6.  Return 

v

.

If 

month

 is not present, this method behaves as if 

month

 was present with the value

getUTCMonth()

getUTCMonth()

. If 

date

 is not present, it behaves as if 

date

 was present with the value

getUTCDate()

getUTCDate()

.

If 

min

 is not present, this method behaves as if 

min

 was present with the value

getUTCMinutes()

getUTCMinutes()

. If 

sec

 is not present, it behaves as if 

sec

 was present with the value

getUTCSeconds()

getUTCSeconds()

. If 

ms

 is not present, it behaves as if 

ms

 was present with the value

getUTCMilliseconds()

getUTCMilliseconds()

.

21.4.4.30  Date.prototype.setUTCHours ( 

hour

 [ , 

min

 [ , 

sec

 [ , 

ms

 ] ] ] )

21.4.4.31  Date.prototype.setUTCMilliseconds ( 

ms

 )

21.4.4.32  Date.prototype.setUTCMinutes ( 

min

 [ , 

sec

 [ , 

ms

 ] ] )

546

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  Let 

m

 be ? 

ToNumber

(

min

).

3.  If 

sec

 is not present, let 

s

 be 

SecFromTime

(

t

).

4.  Else,

a.  Let 

s

 be ? 

ToNumber

(

sec

).

5.  If 

ms

 is not present, let 

milli

 be 

msFromTime

(

t

).

6.  Else,

a.  Let 

milli

 be ? 

ToNumber

(

ms

).

7.  Let 

date

 be 

MakeDate

(

Day

(

t

), 

MakeTime

(

HourFromTime

(

t

), 

m

s

milli

)).

8.  Let 

v

 be 

TimeClip

(

date

).

9.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

10.  Return 

v

.

The 

"length"

 property of the 

setUTCMinutes

setUTCMinutes

 method is 

3

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  Let 

m

 be ? 

ToNumber

(

month

).

3.  If 

date

 is not present, let 

dt

 be 

DateFromTime

(

t

).

4.  Else,

a.  Let 

dt

 be ? 

ToNumber

(

date

).

5.  Let 

newDate

 be 

MakeDate

(

MakeDay

(

YearFromTime

(

t

), 

m

dt

), 

TimeWithinDay

(

t

)).

6.  Let 

v

 be 

TimeClip

(

newDate

).

7.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

8.  Return 

v

.

The 

"length"

 property of the 

setUTCMonth

setUTCMonth

 method is 

2

𝔽

.

NOTE

The following steps are performed:

1.  Let 

t

 be ? 

thisTimeValue

(

this

 value).

2.  Let 

s

 be ? 

ToNumber

(

sec

).

3.  If 

ms

 is not present, let 

milli

 be 

msFromTime

(

t

).

4.  Else,

If 

sec

 is not present, this method behaves as if 

sec

 was present with the value

getUTCSeconds()

getUTCSeconds()

. If 

ms

 is not present, it function behaves as if 

ms

 was present with the

value return by 

getUTCMilliseconds()

getUTCMilliseconds()

.

If 

date

 is not present, this method behaves as if 

date

 was present with the value

getUTCDate()

getUTCDate()

.

21.4.4.33  Date.prototype.setUTCMonth ( 

month

 [ , 

date

 ] )

21.4.4.34  Date.prototype.setUTCSeconds ( 

sec

 [ , 

ms

 ] )

547

a.  Let 

milli

 be ? 

ToNumber

(

ms

).

5.  Let 

date

 be 

MakeDate

(

Day

(

t

), 

MakeTime

(

HourFromTime

(

t

), 

MinFromTime

(

t

), 

s

milli

)).

6.  Let 

v

 be 

TimeClip

(

date

).

7.  Set the [[DateValue]] internal slot of 

this Date object

 to 

v

.

8.  Return 

v

.

The 

"length"

 property of the 

setUTCSeconds

setUTCSeconds

 method is 

2

𝔽

.

NOTE

The following steps are performed:

1.  Let 

O

 be 

this Date object

.

2.  Let 

tv

 be ? 

thisTimeValue

(

O

).

3.  If 

tv

 is 

NaN

, return 

"Invalid Date"

.

4.  Let 

t

 be 

LocalTime

(

tv

).

5.  Return 

DateString

(

t

).

If 

this time value

 is not a finite Number or if it corresponds with a year that cannot be represented in the 

Date Time

String Format

, this function throws a 

RangeError

 exception. Otherwise, it returns a String representation of 

this time

value

 in that format on the UTC time scale, including all format elements and the UTC offset representation 

"Z"

.

This function provides a String representation of a Date object for use by 

JSON.stringify

JSON.stringify

 (

25.5.2

).

When the 

toJSON

toJSON

 method is called with argument 

key

, the following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

tv

 be ? 

ToPrimitive

(

O

number

).

3.  If 

Type

(

tv

) is Number and 

tv

 is not finite, return 

null

.

4.  Return ? 

Invoke

(

O

"toISOString"

).

NOTE 1

NOTE 2

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

If 

ms

 is not present, this method behaves as if 

ms

 was present with the value

getUTCMilliseconds()

getUTCMilliseconds()

.

The argument is ignored.

The 

toJSON

toJSON

 function is intentionally generic; it does not require that its 

this

 value be a Date

object. Therefore, it can be transferred to other kinds of objects for use as a method. However, it
does require that any such object have a 

toISOString

toISOString

 method.

21.4.4.35  Date.prototype.toDateString ( )

21.4.4.36  Date.prototype.toISOString ( )

21.4.4.37  Date.prototype.toJSON ( 

key

 )

21.4.4.38  Date.prototype.toLocaleDateString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

548

Date.prototype.toLocaleDateString

Date.prototype.toLocaleDateString

 method as specified in the ECMA-402 specification. If an

ECMAScript implementation does not include the ECMA-402 API the following specification of the

toLocaleDateString

toLocaleDateString

 method is used.

This function returns a String value. The contents of the String are 

implementation-defined

, but are intended to

represent the “date” portion of the Date in the current time zone in a convenient, human-readable form that
corresponds to the conventions of the 

host environment

's current locale.

The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations
that do not include ECMA-402 support must not use those parameter positions for anything else.

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

Date.prototype.toLocaleString

Date.prototype.toLocaleString

 method as specified in the ECMA-402 specification. If an ECMAScript

implementation does not include the ECMA-402 API the following specification of the 

toLocaleString

toLocaleString

 method

is used.

This function returns a String value. The contents of the String are 

implementation-defined

, but are intended to

represent the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions
of the 

host environment

's current locale.

The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations
that do not include ECMA-402 support must not use those parameter positions for anything else.

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

Date.prototype.toLocaleTimeString

Date.prototype.toLocaleTimeString

 method as specified in the ECMA-402 specification. If an

ECMAScript implementation does not include the ECMA-402 API the following specification of the

toLocaleTimeString

toLocaleTimeString

 method is used.

This function returns a String value. The contents of the String are 

implementation-defined

, but are intended to

represent the “time” portion of the Date in the current time zone in a convenient, human-readable form that
corresponds to the conventions of the 

host environment

's current locale.

The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations
that do not include ECMA-402 support must not use those parameter positions for anything else.

The following steps are performed:

1.  Let 

tv

 be ? 

thisTimeValue

(

this

 value).

2.  Return 

ToDateString

(

tv

).

NOTE 1

For any Date object 

dd

 such that 

d.[[DateValue]]

d.[[DateValue]]

 is evenly divisible by 1000, the result of

Date.parse(d.toString())

Date.parse(d.toString())

 = 

d.valueOf()

d.valueOf()

. See 

21.4.3.2

.

21.4.4.39  Date.prototype.toLocaleString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

21.4.4.40  Date.prototype.toLocaleTimeString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

21.4.4.41  Date.prototype.toString ( )

549

NOTE 2

The abstract operation TimeString takes argument 

tv

. It performs the following steps when called:

1. 

Assert

Type

(

tv

) is Number.

2. 

Assert

tv

 is not 

NaN

.

3.  Let 

hour

 be the String representation of 

HourFromTime

(

tv

), formatted as a two-digit decimal number, padded

to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

4.  Let 

minute

 be the String representation of 

MinFromTime

(

tv

), formatted as a two-digit decimal number, padded

to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

5.  Let 

second

 be the String representation of 

SecFromTime

(

tv

), formatted as a two-digit decimal number, padded

to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

6.  Return the 

string-concatenation

 of 

hour

":"

minute

":"

second

, the code unit 0x0020 (SPACE), and 

"GMT"

.

The abstract operation DateString takes argument 

tv

. It performs the following steps when called:

1. 

Assert

Type

(

tv

) is Number.

2. 

Assert

tv

 is not 

NaN

.

3.  Let 

weekday

 be the Name of the entry in 

Table 52

 with the Number 

WeekDay

(

tv

).

4.  Let 

month

 be the Name of the entry in 

Table 53

 with the Number 

MonthFromTime

(

tv

).

5.  Let 

day

 be the String representation of 

DateFromTime

(

tv

), formatted as a two-digit decimal number, padded to

the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

6.  Let 

yv

 be 

YearFromTime

(

tv

).

7.  If 

yv

 

 

+0

𝔽

, let 

yearSign

 be the empty String; otherwise, let 

yearSign

 be 

"-"

.

8.  Let 

year

 be the String representation of 

abs

(

(

yv

)), formatted as a decimal number.

9.  Let 

paddedYear

 be ! 

StringPad

(

year

4

𝔽

"0"

start

).

10.  Return the 

string-concatenation

 of 

weekday

, the code unit 0x0020 (SPACE), 

month

, the code unit 0x0020

(SPACE), 

day

, the code unit 0x0020 (SPACE), 

yearSign

, and 

paddedYear

.

Table 52: Names of days of the week

Number Name

+0

𝔽

"Sun"

1

𝔽

"Mon"

2

𝔽

"Tue"

3

𝔽

"Wed"

4

𝔽

"Thu"

5

𝔽

"Fri"

6

𝔽

"Sat"

The 

toString

toString

 function is not generic; it throws a 

TypeError

 exception if its 

this

 value is not a

Date object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

21.4.4.41.1  TimeString ( 

tv

 )

21.4.4.41.2  DateString ( 

tv

 )

550

Table 53: Names of months of the year

Number Name

+0

𝔽

"Jan"

1

𝔽

"Feb"

2

𝔽

"Mar"

3

𝔽

"Apr"

4

𝔽

"May"

5

𝔽

"Jun"

6

𝔽

"Jul"

7

𝔽

"Aug"

8

𝔽

"Sep"

9

𝔽

"Oct"

10

𝔽

"Nov"

11

𝔽

"Dec"

The abstract operation TimeZoneString takes argument 

tv

. It performs the following steps when called:

1. 

Assert

Type

(

tv

) is Number.

2. 

Assert

tv

 is not 

NaN

.

3.  Let 

offset

 be 

LocalTZA

(

tv

true

).

4.  If 

offset

 

 

+0

𝔽

, then

a.  Let 

offsetSign

 be 

"+"

.

b.  Let 

absOffset

 be 

offset

.

5.  Else,

a.  Let 

offsetSign

 be 

"-"

.

b.  Let 

absOffset

 be -

offset

.

6.  Let 

offsetMin

 be the String representation of 

MinFromTime

(

absOffset

), formatted as a two-digit decimal number,

padded to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

7.  Let 

offsetHour

 be the String representation of 

HourFromTime

(

absOffset

), formatted as a two-digit decimal

number, padded to the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

8.  Let 

tzName

 be an 

implementation-defined

 string that is either the empty String or the 

string-concatenation

 of

the code unit 0x0020 (SPACE), the code unit 0x0028 (LEFT PARENTHESIS), an 

implementation-defined

timezone name, and the code unit 0x0029 (RIGHT PARENTHESIS).

9.  Return the 

string-concatenation

 of 

offsetSign

offsetHour

offsetMin

, and 

tzName

.

21.4.4.41.3  TimeZoneString ( 

tv

 )

21.4.4.41.4  ToDateString ( 

tv

 )

551

The abstract operation ToDateString takes argument 

tv

. It performs the following steps when called:

1. 

Assert

Type

(

tv

) is Number.

2.  If 

tv

 is 

NaN

, return 

"Invalid Date"

.

3.  Let 

t

 be 

LocalTime

(

tv

).

4.  Return the 

string-concatenation

 of 

DateString

(

t

), the code unit 0x0020 (SPACE), 

TimeString

(

t

), and

TimeZoneString

(

tv

).

The following steps are performed:

1.  Let 

O

 be 

this Date object

.

2.  Let 

tv

 be ? 

thisTimeValue

(

O

).

3.  If 

tv

 is 

NaN

, return 

"Invalid Date"

.

4.  Let 

t

 be 

LocalTime

(

tv

).

5.  Return the 

string-concatenation

 of 

TimeString

(

t

) and 

TimeZoneString

(

tv

).

The 

toUTCString

toUTCString

 method returns a String value representing the instance in time corresponding to 

this time

value

. The format of the String is based upon "HTTP-date" from RFC 7231, generalized to support the full range of

times supported by ECMAScript Date objects. It performs the following steps when called:

1.  Let 

O

 be 

this Date object

.

2.  Let 

tv

 be ? 

thisTimeValue

(

O

).

3.  If 

tv

 is 

NaN

, return 

"Invalid Date"

.

4.  Let 

weekday

 be the Name of the entry in 

Table 52

 with the Number 

WeekDay

(

tv

).

5.  Let 

month

 be the Name of the entry in 

Table 53

 with the Number 

MonthFromTime

(

tv

).

6.  Let 

day

 be the String representation of 

DateFromTime

(

tv

), formatted as a two-digit decimal number, padded to

the left with the code unit 0x0030 (DIGIT ZERO) if necessary.

7.  Let 

yv

 be 

YearFromTime

(

tv

).

8.  If 

yv

 

 

+0

𝔽

, let 

yearSign

 be the empty String; otherwise, let 

yearSign

 be 

"-"

.

9.  Let 

year

 be the String representation of 

abs

(

(

yv

)), formatted as a decimal number.

10.  Let 

paddedYear

 be ! 

StringPad

(

year

4

𝔽

"0"

start

).

11.  Return the 

string-concatenation

 of 

weekday

","

, the code unit 0x0020 (SPACE), 

day

, the code unit 0x0020

(SPACE), 

month

, the code unit 0x0020 (SPACE), 

yearSign

paddedYear

, the code unit 0x0020 (SPACE), and

TimeString

(

tv

).

The following steps are performed:

1.  Return ? 

thisTimeValue

(

this

 value).

This function is called by ECMAScript language operators to convert a Date object to a primitive value. The allowed
values for 

hint

 are 

"default"

"number"

, and 

"string"

. Date objects, are unique among built-in ECMAScript object in

21.4.4.42  Date.prototype.toTimeString ( )

21.4.4.43  Date.prototype.toUTCString ( )

21.4.4.44  Date.prototype.valueOf ( )

21.4.4.45  Date.prototype [ @@toPrimitive ] ( 

hint

 )

552

that they treat 

"default"

 as being equivalent to 

"string"

, All other built-in ECMAScript objects treat 

"default"

 as being

equivalent to 

"number"

.

When the 

@@toPrimitive

@@toPrimitive

 method is called with argument 

hint

, the following steps are taken:

1.  Let 

O

 be the 

this

 value.

2.  If 

Type

(

O

) is not Object, throw a 

TypeError

 exception.

3.  If 

hint

 is 

"string"

 or 

"default"

, then

a.  Let 

tryFirst

 be 

string

.

4.  Else if 

hint

 is 

"number"

, then

a.  Let 

tryFirst

 be 

number

.

5.  Else, throw a 

TypeError

 exception.

6.  Return ? 

OrdinaryToPrimitive

(

O

tryFirst

).

The value of the 

"name"

 property of this function is 

"[Symbol.toPrimitive]"

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

Date instances are ordinary objects that inherit properties from the 

Date prototype object

. Date instances also have a

[[DateValue]] internal slot. The [[DateValue]] internal slot is the 

time value

 represented by 

this Date object

.

The String 

constructor

:

is 

%String%

.

is the initial value of the 

"String"

 property of the 

global object

.

creates and initializes a new String object when called as a 

constructor

.

performs a type conversion when called as a function rather than as a 

constructor

.

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 String behaviour must include a 

super

super

 call to the String

constructor

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

When 

String

String

 is called with argument 

value

, the following steps are taken:

1.  If 

value

 is not present, let 

s

 be the empty String.

2.  Else,

a.  If NewTarget is 

undefined

 and 

Type

(

value

) is Symbol, return 

SymbolDescriptiveString

(

value

).

21.4.5  Properties of Date Instances

22  Text Processing

22.1  String Objects

22.1.1  The String Constructor

22.1.1.1  String ( 

value

 )

553

b.  Let 

s

 be ? 

ToString

(

value

).

3.  If NewTarget is 

undefined

, return 

s

.

4.  Return ! 

StringCreate

(

s

, ? 

GetPrototypeFromConstructor

(NewTarget, 

"%String.prototype%"

)).

The String 

constructor

:

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

%Function.prototype%

.

has the following properties:

The 

String.fromCharCode

String.fromCharCode

 function may be called with any number of arguments which form the rest

parameter 

codeUnits

. The following steps are taken:

1.  Let 

length

 be the number of elements in 

codeUnits

.

2.  Let 

elements

 be a new empty 

List

.

3.  For each element 

next

 of 

codeUnits

, do

a.  Let 

nextCU

ToUint16

(

next

)).

b.  Append 

nextCU

 to the end of 

elements

.

4.  Return the String value whose code units are the elements in the 

List

 

elements

. If 

codeUnits

 is empty, the empty

String is returned.

The 

"length"

 property of the 

fromCharCode

fromCharCode

 function is 

1

𝔽

.

The 

String.fromCodePoint

String.fromCodePoint

 function may be called with any number of arguments which form the rest

parameter 

codePoints

. The following steps are taken:

1.  Let 

result

 be the empty String.

2.  For each element 

next

 of 

codePoints

, do

a.  Let 

nextCP

 be ? 

ToNumber

(

next

).

b.  If ! 

IsIntegralNumber

(

nextCP

) is 

false

, throw a 

RangeError

 exception.

nextCP

nextCP

) > 0x10FFFF, throw a 

RangeError

 exception.

d.  Set 

result

 to the 

string-concatenation

 of 

result

 and ! 

UTF16EncodeCodePoint

(

nextCP

)).

3. 

Assert

: If 

codePoints

 is empty, then 

result

 is the empty String.

4.  Return 

result

.

The 

"length"

 property of the 

fromCodePoint

fromCodePoint

 function is 

1

𝔽

.

The initial value of 

String.prototype

String.prototype

 is the 

String prototype object

.

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

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

22.1.2  Properties of the String Constructor

22.1.2.1  String.fromCharCode ( ...

codeUnits

 )

22.1.2.2  String.fromCodePoint ( ...

codePoints

 )

22.1.2.3  String.prototype

22.1.2.4  String.raw ( 

template

, ...

substitutions

 )

554

The 

String.raw

String.raw

 function may be called with a variable number of arguments. The first argument is 

template

 and

the remainder of the arguments form the 

List

 

substitutions

. The following steps are taken:

1.  Let 

numberOfSubstitutions

 be the number of elements in 

substitutions

.

2.  Let 

cooked

 be ? 

ToObject

(

template

).

3.  Let 

raw

 be ? 

ToObject

(? 

Get

(

cooked

"raw"

)).

4.  Let 

literalSegments

 be ? 

LengthOfArrayLike

(

raw

).

5.  If 

literalSegments

 

 0, return the empty String.

6.  Let 

stringElements

 be a new empty 

List

.

7.  Let 

nextIndex

 be 0.

8.  Repeat,

a.  Let 

nextKey

 be ! 

ToString

(

(

nextIndex

)).

b.  Let 

nextSeg

 be ? 

ToString

(? 

Get

(

raw

nextKey

)).

c.  Append the code unit elements of 

nextSeg

 to the end of 

stringElements

.

d.  If 

nextIndex

 + 1 = 

literalSegments

, then

i.  Return the String value whose code units are the elements in the 

List

 

stringElements

. If

stringElements

 has no elements, the empty String is returned.

e.  If 

nextIndex

 < 

numberOfSubstitutions

, let 

next

 be 

substitutions

[

nextIndex

].

f.  Else, let 

next

 be the empty String.

g.  Let 

nextSub

 be ? 

ToString

(

next

).

h.  Append the code unit elements of 

nextSub

 to the end of 

stringElements

.

i.  Set 

nextIndex

 to 

nextIndex

 + 1.

NOTE

The 

String prototype object

:

is 

%String.prototype%

.

is a 

String exotic object

 and has the internal methods specified for such objects.

has a [[StringData]] internal slot whose value is the empty String.
has a 

"length"

 property whose initial value is 

+0

𝔽

 and whose attributes are { [[Writable]]: 

false

, [[Enumerable]]:

false

, [[Configurable]]: 

false

 }.

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

%Object.prototype%

.

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

this

 value passed to them must be either a String value or an object that has a [[StringData]] internal slot that has been

initialized to a String value.

The abstract operation 

thisStringValue

 takes argument 

value

. It performs the following steps when called:

1.  If 

Type

(

value

) is String, return 

value

.

2.  If 

Type

(

value

) is Object and 

value

 has a [[StringData]] internal slot, then

a.  Let 

s

 be 

value

.[[StringData]].

b. 

Assert

Type

(

s

) is String.

The 

raw

raw

 function is intended for use as a tag function of a Tagged Template (

13.3.11

). When

called as such, the first argument will be a well formed template object and the rest parameter
will contain the substitution values.

22.1.3  Properties of the String Prototype Object

555

c.  Return 

s

.

3.  Throw a 

TypeError

 exception.

NOTE 1

When the 

charAt

charAt

 method is called with one argument 

pos

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

position

 be ? 

ToIntegerOrInfinity

(

pos

).

4.  Let 

size

 be the length of 

S

.

5.  If 

position

 < 0 or 

position

 

 

size

, return the empty String.

6.  Return the String value of length 1, containing one code unit from 

S

, namely the code unit at index 

position

.

NOTE 2

NOTE 1

When the 

charCodeAt

charCodeAt

 method is called with one argument 

pos

, the following steps are taken:

1.  Let 

O

 be ? 

RequireObjectCoercible

(

this

 value).

2.  Let 

S

 be ? 

ToString

(

O

).

3.  Let 

position

 be ? 

ToIntegerOrInfinity

(

pos

).

4.  Let 

size

 be the length of 

S

.

5.  If 

position

 < 0 or 

position

 

 

size

, return 

NaN

.

6.  Return the 

Number value

 for the numeric value of the code unit at index 

position

 within the String 

S

.

NOTE 2

Returns a single element String containing the code unit at index 

pos

 within the String value

resulting from converting this object to a String. If there is no element at that index, the result is
the empty String. The result is a String value, not a String object.

If 

pos

pos

 is an 

integral Number

, then the result of 

x.charAt(pos)

x.charAt(pos)

 is equivalent to the result of

x.substring(pos, pos + 1)

x.substring(pos, pos + 1)

.

The 

charAt

charAt

 function is intentionally generic; it does not require that its 

this

 value be a String

object. Therefore, it can be transferred to other kinds of objects for use as a method.

Returns a Number (a non-negative 

integral Number

 less than 2

16

) that is the numeric value of the

code unit at index 

pos

 within the String resulting from converting this object to a String. If there is

no element at that index, the result is 

NaN

.

The 

charCodeAt

charCodeAt

 function is intentionally generic; it does not require that its 

this

 value be a

String object. Therefore it can be transferred to other kinds of objects for use as a method.

22.1.3.1  String.prototype.charAt ( 

pos

 )

22.1.3.2  String.prototype.charCodeAt ( 

pos

 )

22.1.3.3  String.prototype.codePointAt ( 

pos

 )

556

 

 

 

 

 

 

 

Content      ..     48      49      50      51     ..