6.9 Native Objects


There are certain built-in objects available whenever an ECMA Script program begins execution. One, the global object, is in the scope chain of the executing program. Others are accessible as initial properties of the global object. If that built-in object has a [[Call]] property, then by default, the [[Class]] property of a built-in object is "Function"; otherwise , the [[Class]] property specifies an "Object".

Many built-in objects are functions: they can be invoked with arguments. Some of them are constructor functions intended for use with the new operator. Each built-in function is associated with required arguments and a reference to a Function object that is associated with predefined properties. Each built-in constructor has predefined properties for the prototype object of that constructor and predefined properties returned by a new expression that invokes that constructor.

For additional details, the reader is encouraged to review the detailed list of native objects provided by the ECMA Script 3.0 specification.

6.9.1 Object Objects

When 'Object' constructor is called as part of a new expression, it is a constructor that may create an object. The value of the internal [[Prototype]] property of the Object constructor is the Function prototype object. In addition to the internal properties and the length property (whose value is 1), the Object constructor has the following properties:

Object.prototype : The initial value of Object.prototype is the Object prototype object.

Properties of the Object Prototype Object : The value of the internal [[Prototype]] property of the Object prototype object is null and the value of the internal [[Class]] property is the string "Object".

Object.prototype.constructor : The initial value of Object.prototype.constructor is the built-in Object constructor.

Object.prototype.toString () : When the toString() method is called, the implementation first gets the [[Class]] property of this object, and then returns the string value resulting from concatenating the three strings "[object ", result of step 1, and "]".

Object.prototype.toLocaleString () : This function returns the result of calling toString() . This function is provided to give all objects a generic toLocaleString interface, even though not all may use it. Currently, Array , Number , and Date provide their own locale-sensitive toLocaleString() methods .

Object.prototype.valueOf () : The valueOf() method returns the Object 's this value.

Object.prototype.hasOwnProperty(V) : When the hasOwnProperty() method is called with argument V, first the implementation calls toString(V ).

Object.prototype.isPrototypeOf(V) : Generally, if the value of the [[Prototype]] property of V is not null, return true ; otherwise return false .

Object.prototype.propertyIsEnumerable(V) : First, calls toString(V ). Returns false if the property has the DontEnum attribute or this Object doesn't have a property with the specified name ; otherwise return true .

6.9.2 Joined Objects

Joined objects provide an optimization method for improving performance and reducing memory consumption. Two or more objects joined to each other are effectively indistinguishable except that they may have different internal properties such as [[Scope]] . A script engine may detect cases when the differences in the [[Scope]] properties of two or more joined Function objects are not externally observable. In those cases, it could reuse the same Function object rather than making a set of joined Function objects. When this occurs, two or more Function objects are joined, they have the following special behaviors:

Any time a noninternal property of an object O is created or set, the corresponding property is immediately also created or set with the same value and attributes in all objects joined with O. Any time a noninternal property of an object O is deleted, the corresponding property is immediately also deleted in all objects joined with O.

If objects O and P are joined, they compare as == and === to each other. Joining is transitive and symmetric, so that if objects O and P are joined and objects P and Q are joined, then objects O and Q are also automatically joined.

6.9.3 Function Objects

Every function instance has a [[Call]] property (referencing the method's body), a [[Construct]] property (referencing the function object's constructor), and a [[Scope]] property. The value of the [[Class]] property is the string "Function".

length : The value of the length property is usually an integer that indicates the typical number of arguments expected by the function. However, the language permits the function to be invoked with some other number of arguments. The behavior of a function when invoked on a number of arguments other than the number specified by its length property depends on the function.

prototype : The value of the [[Prototype]] property is used to initialize the internal [[Prototype]] property of a newly created object before the Function object is invoked as a constructor for that newly created object.

[[HasInstance]] (V) : Recursively call the [[Get]] method of that function object with property name "prototype", and return true only when V and the result of step 2 refer to the same object or if they refer to objects joined to each other.

6.9.3.1 Constructing Function Objects

A Function object is constructed using a parameter list specified by FormalParameterList of a function, a body specified by FunctionBody , and a scope chain specified by the [[Scope]] property. The value of the internal [[Prototype]] property of the Function constructor is the Function prototype object. In addition to the internal properties and the length property (whose value is 1), the Function constructor has the Function.prototype (i.e., the [[Prototype]]) property. The initial value of Function.prototype is the Function prototype object.

When Function is called as part of a new expression, it is a constructor: it initializes the newly created object. A [[Prototype]] property is automatically created for every function, to provide for the possibility that the function is used as a constructor. When new Function (p1, p2, , pn, body) is invoked, the last argument specifies the body (executable code) of a function; any preceding arguments specify formal parameters.

It is permissible but not necessary to have one argument for each formal parameter to be specified. For example, all three of the expressions new Function("a", "b", "c", "return a+b+c") , new Function("a, b, c", "return a+b+c") , and new Function("a,b", "c", "return a+b+c") produce the same result.

When Function is called as a function rather than as a constructor, it creates and initializes a new Function object. The call Function(...) is equivalent to the object creation expression new Function(...) with the same arguments. When called with some arguments p 1 , p 2 , ... , p n body (where n might be 0, that is, there are no p arguments, and where body might also not be provided), the implementation creates and returns a new Function object as if the function constructor had been called with the same arguments.

6.9.3.2 Function Prototype Object

The [[Prototype]] property, referring to a function prototype object, is automatically created for every function, to allow for the possibility that the function is used as a constructor. The function prototype object is itself a Function object (its [[Class]] evaluates to the string "Function") that, when invoked, accepts any arguments and returns Undefined . The value of the internal [[Prototype]] property of the Function prototype object is the Object prototype object. It is a function with an empty body; if it is invoked, it merely returns Undefined . The Function prototype object does not have a valueOf property of its own; however, it inherits the valueOf property from the Object prototype object.

The first step in the function construction process allows optimizing the common case of a function A that has a nested function B where B is not dependent on A. In this case the script engine may reuse the same object for B instead of creating a new one every time A is called.

In the case of the code in Example 6.7 a script engine is allowed to join b1 and b2. In fact, it may make b1 and b2 the same object because there is no way to detect the difference between their [[Scope]] properties. On the other hand, a script engine does not join b3 and b4 because their source codes are not equal (recall the earlier definition of joined objects). A script engine does not join b5 and b6 because they were produced by two different calls to eval() and therefore their source codes are not equated. In general, it is likely to be useful to join two Function objects only in the cases where a script engine can prove that the differences between their [[Scope]] properties are not observable, so one object can be reused.

Example 6.7 Object join scenario.
  function A() {   function B(x) {return x*x;}   return B;   }   function C() {   return eval("(function (x) {return x*x;})");   }   var b1 = A();   var b2 = A();   function b3(x) {return x*x;}   function b4(x) {return x*x;}   var b5 = C();   var b6 = C();  

The following are the methods of the Function object:

Function.prototype.constructor : The initial value of Function.prototype.constructor is the built-in Function constructor.

Function.prototype.toString () : An implementation dependent representation of the function is returned.

Function.prototype.apply (thisArg,argArray) : This method performs a function call using the [[Call]] property of this function object. Upon normal execution, the function is passed the ( ToUint32(argArray.length) ) arguments argArray[0], argArray[1], , argArray[ToUint32(argArray.length) “1].

Function.prototype.call (thisArg [ , arg1 [ , arg2, ] ]) : The call method performs a function call using the [[Call]] property of this function object. Under normal operation, called function is passed arg1, arg2, ... as the arguments.

6.9.4 Array Objects

Array objects give special treatment to a certain class of property names . A property name P (in the form of a string value) is an array index if and only if ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal to 2 32 “1. Every Array object has a length property whose value is always a nonnegative integer less than 2 32 . The value of the length property is numerically greater than the name of every property whose name is an array index; whenever a property of an Array object is created or changed, other properties are adjusted as necessary to maintain this invariant. Specifically, whenever a property is added whose name is an array index, the length property is changed, if necessary, to be one more than the numeric value of that array index; and whenever the length property is changed, every property whose name is an array index whose value is not smaller than the new length is automatically deleted. This constraint applies only to properties of the Array object itself and is unaffected by length or index properties that may be inherited from its prototype.

6.9.4.1 The Array Constructor

When Array is called as part of a new expression, it is a constructor: it initializes the newly created object. When the Array function Array ( [ item 1 [ , item 2 [ , ] ] ] ) is called, create and return a new Array object exactly as if the Array constructor had been called with the same arguments. When Array is called as a function rather than as a constructor, it creates and initializes a new Array object. Thus the function call Array( ) is equivalent to the object creation expression new Array( ) with the same arguments.

When new Array([item0[,item 1 [, ]]]) is called, the following property assignment occurs: The [[Prototype]] property of the newly constructed object is set to the original Array prototype object, the one that is the initial value of Array.prototype . The [[Class]] property of the newly constructed object is set to the string "Array". The length property of the newly constructed object is set to the number of arguments.

When new Array(len) is called, the following property assignments occur: The [[Prototype]] property of the newly constructed object is set to the original Array prototype object, the one that is the initial value of Array.prototype . The [[Class]] property of the newly constructed object is set to Array . If the argument len is a Number and ToUint32(len) is equal to len, then the length property of the newly constructed object is set to ToUint32(len) . If the argument len is a Number and ToUint32(len) is not equal to len, a RangeError exception is thrown. If the argument len is not a Number , then the length property of the newly constructed object is set to 1 and the 0 property of the newly constructed object is set to len.

6.9.4.2 Properties of the Array Prototype Object

The value of the internal [[Prototype]] property of the Array prototype object is the Object prototype object. The Array prototype object does not have a valueOf property of its own; however, it inherits the valueOf property from the Object prototype object.

The following are the methods of the Array object:

  • Array.prototype.constructor : The initial value of Array.prototype.constructor is the built-in Array constructor.

  • Array.prototype.toString () : The result of calling this function is the same as if the built-in join method were invoked for this object with no argument. The toString() function throws a TypeError exception if its this value is not an Array object.

  • Array.prototype.toLocaleString () : The elements of the Array are converted to strings using their toLocaleString methods, and these strings are then concatenated , separated by occurrences of a separator string that has been derived in an implementation-dependent, locale-specific way. The result of calling this function is intended to be analogous to the result of toString() , except that the result of this function is intended to be locale specific. The toLocaleString() function throws a TypeError exception if its this value is not an Array object.

  • Array.prototype.concat ( [ item 1 [ , item 2 [ , ] ] ] ) : When the concat() method is called with zero or more arguments ( item 1 , item 2 , etc.), it returns an Array object containing the Array elements of the object followed by the Array elements of each argument in order.

  • Array.prototype.join (separator) : The elements of the Array are converted to strings, and these strings are then concatenated, separated by occurrences of the separator. If no separator is provided, a single comma is used as the separator. The join() method takes one argument: the separator.

  • Array.prototype.pop () : The last element of the Array is removed from the Array object and returned.

  • Array.prototype.push ( [ item 1 [ , item 2 [ , ] ] ] ) : The arguments are appended to the end of the Array in the order in which they appear. The new length property of the Array object is returned as the result of the call.

  • Array.prototype.reverse () : The elements of the Array are rearranged to reverse their order. This reversal is modifying the object itself, that is then returned as the result of the call.

  • Array.prototype.shift () : The first element of the Array is removed from the Array and returned.

  • Array.prototype.unshift ( [ item 1 [ , item 2 [ , ] ] ] ) : The arguments are prepended to the start of the Array , such that their order within the Array object is the same as the order in which they appear in the argument list.

  • Array.prototype.slice (start, end) : The slice() method returns an Array containing the elements of the Array from element start up to, but not including, element end (or through the end of the Array if end is Undefined ). If start is negative, it is treated as (length+start) where length is the length of the Array . If end is negative, it is treated as (length+end) where length, end are the length of the Array and the index of its last element respectively.

  • Array.prototype.splice (start, deleteCount [ , item 1 [ , item 2 [ , ] ] ] ) : When the splice() method is called with two or more arguments start , deleteCount , and ( optionally ) item 1 , item 2 , etc., the deleteCount elements of the Array starting at index start are replaced by the arguments item 1 , item 2 , etc.

  • Array.prototype. sort (comparefn) : The elements are sorted. The sort is not necessarily stable (elements that compare equal do not necessarily remain in their original order). If comparefn() is not Undefined , it should be a function that accepts two arguments x and y and returns a negative value when x<y , returns zero when x=y , and a positive value when x>y .

6.9.4.3 Properties of Array Instances

Array instances inherit properties from the Array prototype object. Array objects use a variation of the [[Put]] method used for other native ECMA Script objects. Assume A is an Array object and P is a string. The length property of this Array object is always numerically greater than the name of every property whose name is an Array index.

6.9.5 String Objects

6.9.5.1 Properties of String Instances

String instances inherit properties from the String prototype object and also have a [[Value]] property and a length property. The [[Value]] property is the string value represented by this String object. The length property specified the number of characters in the String . Once a String object is created, this property is unchanging.

6.9.5.2 The String Constructor

When String is called as part of a new expression, it is a constructor that initializes the newly created object. On invocation of new String([value]) , the [[Prototype]] property is set to the original String prototype object, the one that is the initial value of String.prototype . The [[Class]] property of the newly constructed object is set to the string "String". The [[Value]] property of the newly constructed object is set to ToString(value) , or to the empty string if value is not supplied.

When String is called as a function rather than as a constructor, it performs a type conversion. String([value]) returns a string value (not a String object) computed by ToString(value) . If value is not supplied, the empty string "" is returned.

The value of the internal [[Prototype]] property of the String constructor is the Function prototype object. In addition to the internal properties and the length property (whose value is 1), the String constructor has the following properties:

  • String.prototype : The initial value of String.prototype is the String prototype object.

  • String.fromCharCode ( [ char [ , char 1 [ , ] ] ] ) : Returns a string value containing as many characters as the number of arguments. Each argument specifies one character of the resulting string, with the first argument specifying the first character, and so on, from left to right. An argument is converted to a character by applying the operation ToUint16 and regarding the resulting 16-bit integer as the code point value of a character. If no arguments are supplied, the result is the empty string.

6.9.5.3 String Prototype Object

The String prototype object is itself a String object whose value is an empty string and its [[Class]] property is assigned the string "String". The value of the internal [[Prototype]] property of the String prototype object is the Object prototype object.

  • String.prototype.constructor : The initial value of String.prototype.constructor is the built-in String constructor.

  • String.prototype.toString () : Returns this string's value, which happens to be the same value returned by the valueOf() method. The toString() function throws a TypeError exception if its this value is not a String object.

  • String.prototype.valueOf () : Returns this string value. The valueOf() function throws a TypeError exception if its this value is not a String object.

  • String.prototype.charAt (pos) : Returns a string containing the character at position pos in the string resulting from converting this object to a string. If there is no character at that position, the result is the empty string. The result is a string value, not a String object. If pos is a value of Number type that is an integer, then the result of charAt(pos) is equal to the result of substring(pos, pos+1) .

  • String.prototype.charCodeAt (pos) : Returns a nonnegative integer less than 2 16 representing the code point value of the character at position pos in the string resulting from converting this object to a string. If there is no character at that position, the result is NaN .

  • String.prototype.concat ( [ string 1 [ , string 2 [ , ] ] ] ) : When the concat() method is called with zero or more arguments string 1 , string 2 , etc., it returns a string consisting of the characters of this object (converted to a string) followed by the characters of each of string 1 , string 2 , etc. (where each argument is converted to a string). The result is a string value, not a String object.

  • String.prototype.indexOf (searchString, position) : If searchString appears as a substring of the result of converting this object to a string, at one or more positions that are greater than or equal to position , then the index of the smallest such position is returned; otherwise, -1 is returned. If position is not specified, it defaults to Undefined , and the entire string is searched. The indexOf() method takes two arguments, searchString and position .

  • String.prototype.lastIndexOf (searchString, position) : Same as the indexOf() function described previously, except searches from the end of the string.

  • String.prototype.match (regexp) : Applies the regular expression specified by the result of the expression new RegExp(regexp) . However, if regexp is an object whose [[Class]] property is the string "RegExp", no such replacement is needed, and the regular expression is applied directly.

  • String.prototype.replace (searchValue, replaceValue) : Replaces the pattern specified by searchValue with the string specified by replaceValue according to the standard semantics of regular expressions. The searchValue is specified using the syntax of regular expressions.

  • String.prototype.localeCompare (that) : Returns a number that represents the result of a locale-sensitive string comparison of this object (converted to a string) with that (converted to a string). The two strings are compared in an implementation dependent fashion. The result is intended to order strings in the sort order specified by the system default locale. It is negative, zero, or positive, depending on whether this comes before that in the sort order, the strings are equal, or this comes after that in the sort order, respectively.

  • String.prototype.search (regexp) : Similar to the match() function described previously.

  • String.prototype.slice (start, end) : The slice method takes two arguments, start and end , and returns a substring of the result of converting this object to a string, starting from character position start and running to, but not including, character position end (or through the end of the string if end is Undefined ). If start is negative, it is treated as ( sourceLength + start ) where sourceLength is the length of the string. If end is negative, it is treated as ( sourceLength + end ) where sourceLength is the length of the string. The result is a string value, not a String object.

  • String.prototype.split (separator, limit) : Returns an Array object into which substrings of the result of converting this object to a string have been stored. The substrings are determined by searching from left to right for occurrences of separator ; these occurrences are not part of any substring in the returned Array , but serve to divide up the string value. The value of separator may be a string of any length or it may be a RegExp object (i.e., an object whose [[Class]] property is "RegExp"). The value of separator may be an empty string, an empty regular expression, or a regular expression that can match an empty string; if separator is the empty string, the string is split up into individual characters.

  • String.prototype.substring (start, end) : Returns a substring of the result of converting this object to a string, starting from character position start and running to, but not including, character position end of the string (or through the end of the string is end is Undefined ). The result is a string value, not a String object. If start is larger than end , they are swapped.

  • String.prototype.toLowerCase () : If this object is not already a string, it is converted to a string. The characters in that string are converted one by one to lower case. The result is a string value, not a String object. The characters are converted one by one. The result should be derived according to the case mappings in the Unicode character database.

  • String.prototype.toLocaleLowerCase () : This function works exactly the same as toLowerCase() except that its result is intended to yield the correct result for the host environment's current locale, rather than a locale independent result.

  • String.prototype.toUpperCase () : This function behaves in exactly the same way as String.prototype.toLowerCase , except that characters are mapped to their uppercase equivalents as specified in the Unicode Character Database. The result of s.toUpperCase().toLowerCase() is not necessarily equal to s.toLowerCase() because these functions have context-sensitive behavior.

  • String.prototype.toLocaleUpperCase () : This function works exactly the same as toUpperCase() except that its result is intended to yield the correct result for the host environment's current locale, rather than a locale-independent result.

6.9.6 Date Object

A Date object contains a number indicating a particular instant in time to within a millisecond.

6.9.6.1 The Date Constructor

As all object constructors, the Date constructor could be called as a function. When Date is called as a function rather than as a constructor, it returns a string representing the current time (UTC). The function call Date( ) is not equivalent to the object creation expression new Date( ) with the same arguments. When Date([year [, month [, date [, hours [, minutes [, seconds [, ms ]]]]]]]) is called, all of the arguments are optional; any arguments supplied are accepted but are completely ignored. A string is created and returned as if by the expression (new Date()).toString() .

When Date is called as part of a new expression, it is a constructor: it initializes the newly created object. When new Date(year, month [, date [, hours [, minutes [, seconds [, ms ]]]]]) is called with two to seven arguments, the constructor computes the date from year , month , and (optionally) date , hours , minutes , seconds , and ms . The [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype . The [[Class]] property of the newly constructed object is set to Date .

When new Date() is invoked with no arguments, the [[Prototype]] property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype . The [[Class]] property of the newly constructed object is set to Date . The [[Value]] property of the newly constructed object is set to the current time (UTC).

6.9.6.2 Time

Time is measured in ECMA Script in milliseconds since 01 January, 1970 UTC. Leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ECMAScript number values can represent all integers from “9,007,199,254,740,991 to 9,007,199,254,740,991; this range suffices to measure times to millisecond precision for any instant that is within approximately 285,616 years , either forward or backward, from 01 January, 1970 UTC. The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly “100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC. This gives a range of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC. The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.

6.9.6.3 Day Number and Time within Day

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

6.9.6.4 Year Number

ECMA Script uses an extrapolated Gregorian system to map a day number to a year number and to determine the month and date within that year. In this system, leap years are precisely those which are (divisible by 4) and ((not divisible by 100) or (divisible by 400)). All nonleap years are assumed to 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 x (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 x DayFromYear(y) , and a time value determines a year by YearFromTime(t) = the largest integer y ( closest to positive infinity) such that TimeFromYear(y) = t .

6.9.6.5 Month Number

Months are identified by an integer in the range 0 to 11, inclusive. The mapping MonthFromTime(t) from a time value t to a month number is defined by Table 6.24 where DayWith inYear(t) = Day(t)-DayFromYear(YearFromTime(t)). Note that MonthFromTime(0) = 0 , corresponds to Thursday, 01 January, 1970.

Table 6.24. Value of MonthFromTime(t)

MonthFromTime(t)

Case

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)

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.

6.9.6.6 Date Number

A date number is identified by an integer in the range 1 through 31, inclusive. The mapping DateFromTime(t) from a time value t to a month number is defined by Table 6.25.

Table 6.25. Value of DateFromTime(t).

MonthFromTime(t)

Case

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

6.9.6.7 Week Day

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 , corresponds to Thursday, 01 January, 1970.

6.9.6.8 Local Time Zone Adjustment

The local time zone adjustment is a value LocalTZA measured in milliseconds which when added to UTC represents the local standard time. Daylight saving time is not reflected by LocalTZA . The value LocalTZA does not vary with time but depends only on the geographic location.

6.9.6.9 Daylight Saving Time Adjustment

The algorithm to determine the daylight saving time adjustment DaylightSavingTA(t) , measured in milliseconds, must depend only on four items: (a) the time since the beginning of the year t “TimeFromYear(YearFromTime(t)), (b) whether t is in a leap year, (c) the weekday of the beginning of the year WeekDay(TimeFromYear(YearFromTime(t)) , and (d) the geographic location.

An attempt is made to determine whether the exact time was subject to daylight saving time, but just whether daylight saving time would have been in effect if the current daylight saving time algorithm had been used at the time. This avoids complications such as taking into account the years that the locale observed daylight saving time year round.

If the host environment provides functionality for determining daylight saving time, the implementation of ECMA Script is free to map the year in question to an equivalent year (same leap year-ness and same starting week day for the year) for which the host environment provides daylight saving time information. The only restriction is that all equivalent years should produce the same result.

6.9.6.10 Local Time Conversions

Conversion from UTC to local time is defined by LocalTime(t) = t + LocalTZA + DaylightSavingTA(t) . Conversion from local time to UTC is defined by UTC(t)=t “ LocalTZA “DaylightSavingTA(t “LocalTZA) . Note that UTC(LocalTime(t)) is not necessarily always equal to t .

6.9.6.11 Hours, Minutes, Second, and Milliseconds

The following functions 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 = msPerSecond x SecondsPerMinute = 60000, msPerHour = msPerMinute x MinutesPerHour = 3600000 .

6.9.6.12 Make Operators

MakeTime ( hour , min, sec, ms) The operator MakeTime calculates a number of milliseconds from its four arguments, which must be ECMA Script number values.

MakeDay (year, month, date) The operator MakeDay calculates a number of days from its three arguments, which must be ECMA Script number values.

MakeDate (day, time) The operator MakeDate calculates a number of milliseconds from its two arguments, which must be ECMA Script number values.



ITV Handbook. Technologies and Standards
ITV Handbook: Technologies and Standards
ISBN: 0131003127
EAN: 2147483647
Year: 2003
Pages: 170

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net