~ubuntu-branches/ubuntu/wily/mozjs17/wily

« back to all changes in this revision

Viewing changes to js/src/tests/ecma_3/Date/15.9.5.5.js

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// |reftest| random-if(xulRuntime.OS=="Linux")
 
2
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
3
/* This Source Code Form is subject to the terms of the Mozilla Public
 
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
6
 
 
7
 
 
8
/**
 
9
   File Name:          15.9.5.5.js
 
10
   ECMA Section: 15.9.5.5 Date.prototype.toLocaleString()
 
11
   Description:
 
12
   This function returns a string value. The contents of the string are
 
13
   implementation dependent, but are intended to represent the "date"
 
14
   portion of the Date in the current time zone in a convenient,
 
15
   human-readable form.   We can't test the content of the string, 
 
16
   but can verify that the string is parsable by Date.parse
 
17
 
 
18
   The toLocaleString function is not generic; it generates a runtime error
 
19
   if its 'this' value is not a Date object. Therefore it cannot be transferred
 
20
   to other kinds of objects for use as a method.
 
21
 
 
22
   Note: This test isn't supposed to work with a non-English locale per spec.
 
23
 
 
24
   Author:  pschwartau@netscape.com
 
25
   Date:      14 november 2000
 
26
*/
 
27
 
 
28
var SECTION = "15.9.5.5";
 
29
var VERSION = "ECMA_3"; 
 
30
var TITLE   = "Date.prototype.toLocaleString()"; 
 
31
  
 
32
var status = '';
 
33
var actual = ''; 
 
34
var expect = '';
 
35
 
 
36
 
 
37
startTest();
 
38
writeHeaderToLog( SECTION + " "+ TITLE);
 
39
 
 
40
// first, some generic tests -
 
41
 
 
42
status = "typeof (now.toLocaleString())"; 
 
43
actual =   typeof (now.toLocaleString());
 
44
expect = "string";
 
45
addTestCase();
 
46
 
 
47
status = "Date.prototype.toLocaleString.length";  
 
48
actual =  Date.prototype.toLocaleString.length;
 
49
expect =  0;  
 
50
addTestCase();
 
51
 
 
52
// Date.parse is accurate to the second;  valueOf() to the millisecond  -
 
53
status = "Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000";  
 
54
actual =   Math.abs(Date.parse(now.toLocaleString()) -  now.valueOf()) < 1000;
 
55
expect = true;
 
56
addTestCase();
 
57
 
 
58
 
 
59
 
 
60
// 1970
 
61
addDateTestCase(0);
 
62
addDateTestCase(TZ_ADJUST);  
 
63
 
 
64
  
 
65
// 1900
 
66
addDateTestCase(TIME_1900);
 
67
addDateTestCase(TIME_1900 -TZ_ADJUST);
 
68
 
 
69
  
 
70
// 2000
 
71
addDateTestCase(TIME_2000);
 
72
addDateTestCase(TIME_2000 -TZ_ADJUST);
 
73
 
 
74
   
 
75
// 29 Feb 2000
 
76
addDateTestCase(UTC_29_FEB_2000);
 
77
addDateTestCase(UTC_29_FEB_2000 - 1000);   
 
78
addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
 
79
 
 
80
 
 
81
// 2005
 
82
addDateTestCase(UTC_1_JAN_2005);
 
83
addDateTestCase(UTC_1_JAN_2005 - 1000);
 
84
addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST);
 
85
  
 
86
 
 
87
 
 
88
//-----------------------------------------------------------------------------------------------------
 
89
test();
 
90
//-----------------------------------------------------------------------------------------------------
 
91
 
 
92
 
 
93
function addTestCase()
 
94
{
 
95
  AddTestCase(
 
96
    status,
 
97
    expect,
 
98
    actual);
 
99
}
 
100
 
 
101
 
 
102
function addDateTestCase(date_given_in_milliseconds)
 
103
{
 
104
  var givenDate = new Date(date_given_in_milliseconds);
 
105
 
 
106
  status = 'Date.parse('   +   givenDate   +   ').toLocaleString())';  
 
107
  actual =  Date.parse(givenDate.toLocaleString());
 
108
  expect = date_given_in_milliseconds;
 
109
  addTestCase();
 
110
}
 
111