1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
ECMA Section: 15.9.5.4 Date.prototype.toTimeString()
10
This function returns a string value. The contents of the string are
11
implementation dependent, but are intended to represent the "time"
12
portion of the Date in the current time zone in a convenient,
13
human-readable form. We test the content of the string by checking
14
that d.toDateString() + d.toTimeString() == d.toString()
16
Author: pschwartau@netscape.com
17
Date: 14 november 2000
18
Revised: 07 january 2002 because of a change in JS Date format:
20
See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey)
21
See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino)
23
//-----------------------------------------------------------------------------
24
var SECTION = "15.9.5.4";
25
var VERSION = "ECMA_3";
26
var TITLE = "Date.prototype.toTimeString()";
34
var reducedDateString = '';
35
var hopeThisIsTimeString = '';
36
var cnEmptyString = '';
37
var cnERR ='OOPS! FATAL ERROR: no regexp match in extractTimeString()';
40
writeHeaderToLog( SECTION + " "+ TITLE);
42
// first, a couple of generic tests -
44
status = "typeof (now.toTimeString())";
45
actual = typeof (now.toTimeString());
49
status = "Date.prototype.toTimeString.length";
50
actual = Date.prototype.toTimeString.length;
56
addDateTestCase(TZ_ADJUST);
60
addDateTestCase(TIME_1900);
61
addDateTestCase(TIME_1900 - TZ_ADJUST);
65
addDateTestCase(TIME_2000);
66
addDateTestCase(TIME_2000 - TZ_ADJUST);
70
addDateTestCase(UTC_29_FEB_2000);
71
addDateTestCase(UTC_29_FEB_2000 - 1000);
72
addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
76
addDateTestCase( TIME_NOW);
77
addDateTestCase( TIME_NOW - TZ_ADJUST);
81
addDateTestCase(UTC_1_JAN_2005);
82
addDateTestCase(UTC_1_JAN_2005 - 1000);
83
addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
85
//-----------------------------------------------------------------------------------------------------
87
//-----------------------------------------------------------------------------------------------------
89
function addTestCase()
98
function addDateTestCase(date_given_in_milliseconds)
100
givenDate = new Date(date_given_in_milliseconds);
102
status = '(' + givenDate + ').toTimeString()';
103
actual = givenDate.toTimeString();
104
expect = extractTimeString(givenDate);
110
* As of 2002-01-07, the format for JavaScript dates changed.
111
* See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey)
112
* See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino)
114
* WAS: Mon Jan 07 13:40:34 GMT-0800 (Pacific Standard Time) 2002
115
* NOW: Mon Jan 07 2002 13:40:34 GMT-0800 (Pacific Standard Time)
117
* Thus, use a regexp of the form /date.toDateString()(.*)$/
118
* to capture the TimeString into the first backreference -
120
function extractTimeString(date)
122
regexp = new RegExp(date.toDateString() + '(.*)' + '$');
126
hopeThisIsTimeString = date.toString().match(regexp)[1];
133
// trim any leading or trailing spaces -
134
return trimL(trimR(hopeThisIsTimeString));
140
if (!s) {return cnEmptyString;};
141
for (var i = 0; i!=s.length; i++) {if (s[i] != ' ') {break;}}
142
return s.substring(i);
148
if (!s) {return cnEmptyString;};
149
for (var i = (s.length - 1); i!=-1; i--) {if (s[i] != ' ') {break;}}
150
return s.substring(0, i+1);