1 /* The contents of this file are subject to the Netscape Public 2 * License Version 1.1 (the "License"); you may not use this file 3 * except in compliance with the License. You may obtain a copy of 4 * the License at http://www.mozilla.org/NPL/ 5 * 6 * Software distributed under the License is distributed on an "AS 7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 8 * implied. See the License for the specific language governing 9 * rights and limitations under the License. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 14 * The Initial Developer of the Original Code is Netscape Communications 15 * Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22 /** 23 File Name: 15.9.5.5.js 24 ECMA Section: 15.9.5.5 25 Description: Date.prototype.getYear 26 27 This function is specified here for backwards compatibility only. The 28 function getFullYear is much to be preferred for nearly all purposes, 29 because it avoids the "year 2000 problem." 30 31 1. Let t be this time value. 32 2. If t is NaN, return NaN. 33 3. Return YearFromTime(LocalTime(t)) 1900. 34 35 Author: christine (at) netscape.com 36 Date: 12 november 1997 37 */ 38 39 var SECTION = "15.9.5.5"; 40 var VERSION = "ECMA_1"; 41 startTest(); 42 var TITLE = "Date.prototype.getYear()"; 43 44 writeHeaderToLog( SECTION + " "+ TITLE); 45 46 var testcases = new Array(); 47 48 var TZ_ADJUST = TZ_DIFF * msPerHour; 49 50 // get the current time 51 var now = (new Date()).valueOf(); 52 53 // get time for 29 feb 2000 54 55 var UTC_FEB_29_2000 = TIME_2000 + 31*msPerDay + 28*msPerHour; 56 57 addTestCase( now ); 58 addTestCase( TIME_YEAR_0 ); 59 addTestCase( TIME_1970 ); 60 addTestCase( TIME_1900 ); 61 addTestCase( TIME_2000 ); 62 addTestCase( UTC_FEB_29_2000 ); 63 64 testcases[tc++] = new TestCase( SECTION, 65 "(new Date(NaN)).getYear()", 66 NaN, 67 (new Date(NaN)).getYear() ); 68 69 testcases[tc++] = new TestCase( SECTION, 70 "Date.prototype.getYear.length", 71 0, 72 Date.prototype.getYear.length ); 73 74 test(); 75 function addTestCase( t ) { 76 testcases[tc++] = new TestCase( SECTION, 77 "(new Date("+t+")).getYear()", 78 GetYear(YearFromTime(LocalTime(t))), 79 (new Date(t)).getYear() ); 80 81 testcases[tc++] = new TestCase( SECTION, 82 "(new Date("+(t+1)+")).getYear()", 83 GetYear(YearFromTime(LocalTime(t+1))), 84 (new Date(t+1)).getYear() ); 85 86 testcases[tc++] = new TestCase( SECTION, 87 "(new Date("+(t-1)+")).getYear()", 88 GetYear(YearFromTime(LocalTime(t-1))), 89 (new Date(t-1)).getYear() ); 90 91 testcases[tc++] = new TestCase( SECTION, 92 "(new Date("+(t-TZ_ADJUST)+")).getYear()", 93 GetYear(YearFromTime(LocalTime(t-TZ_ADJUST))), 94 (new Date(t-TZ_ADJUST)).getYear() ); 95 96 testcases[tc++] = new TestCase( SECTION, 97 "(new Date("+(t+TZ_ADJUST)+")).getYear()", 98 GetYear(YearFromTime(LocalTime(t+TZ_ADJUST))), 99 (new Date(t+TZ_ADJUST)).getYear() ); 100 } 101 function GetYear( year ) { 102 /* 103 if ( year >= 1900 && year < 2000 ) { 104 return year - 1900; 105 } else { 106 return year; 107 } 108 */ 109 return year - 1900; 110 } 111 function test() { 112 for ( tc=0; tc < testcases.length; tc++ ) { 113 testcases[tc].passed = writeTestCaseResult( 114 testcases[tc].expect, 115 testcases[tc].actual, 116 testcases[tc].description +" = "+ 117 testcases[tc].actual ); 118 119 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 120 } 121 stopTest(); 122 return ( testcases ); 123 } 124