1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Date/regress-301738-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 301738; 1.11 +var summary = 'Date parse compatibilty with MSIE'; 1.12 +var actual = ''; 1.13 +var expect = ''; 1.14 + 1.15 +printBugNumber(BUGNUMBER); 1.16 +printStatus (summary); 1.17 + 1.18 +/* 1.19 + Case 2. The input string is of the form "f/m/l" where f, m and l are 1.20 + integers, e.g. 7/16/45. 1.21 + Adjust the mon, mday and year values to achieve 100% MSIE 1.22 + compatibility. 1.23 + a. If 0 <= f < 70, f/m/l is interpreted as month/day/year. 1.24 + i. If year < 100, it is the number of years after 1900 1.25 + ii. If year >= 100, it is the number of years after 0. 1.26 + b. If 70 <= f < 100 1.27 + i. If m < 70, f/m/l is interpreted as 1.28 + year/month/day where year is the number of years after 1.29 + 1900. 1.30 + ii. If m >= 70, the date is invalid. 1.31 + c. If f >= 100 1.32 + i. If m < 70, f/m/l is interpreted as 1.33 + year/month/day where year is the number of years after 0. 1.34 + ii. If m >= 70, the date is invalid. 1.35 +*/ 1.36 + 1.37 +var f; 1.38 +var m; 1.39 +var l; 1.40 + 1.41 +function newDate(f, m, l) 1.42 +{ 1.43 + return new Date(f + '/' + m + '/' + l); 1.44 +} 1.45 + 1.46 +function newDesc(f, m, l) 1.47 +{ 1.48 + return f + '/' + m + '/' + l; 1.49 +} 1.50 + 1.51 +// 2.a.i 1.52 +f = 0; 1.53 +m = 0; 1.54 +l = 0; 1.55 + 1.56 +expect = (new Date(l, f-1, m)).toDateString(); 1.57 +actual = newDate(f, m, l).toDateString(); 1.58 +reportCompare(expect, actual, newDesc(f, m, l)); 1.59 + 1.60 +f = 0; 1.61 +m = 0; 1.62 +l = 100; 1.63 + 1.64 +expect = (new Date(l, f-1, m)).toDateString(); 1.65 +actual = newDate(f, m, l).toDateString(); 1.66 +reportCompare(expect, actual, newDesc(f, m, l)); 1.67 + 1.68 +// 2.a.ii 1.69 +f = 0; 1.70 +m = 24; 1.71 +l = 100; 1.72 + 1.73 +expect = (new Date(l, f-1, m)).toDateString(); 1.74 +actual = newDate(f, m, l).toDateString(); 1.75 +reportCompare(expect, actual, newDesc(f, m, l)); 1.76 + 1.77 +f = 0; 1.78 +m = 24; 1.79 +l = 2100; 1.80 + 1.81 +expect = (new Date(l, f-1, m)).toDateString(); 1.82 +actual = newDate(f, m, l).toDateString(); 1.83 +reportCompare(expect, actual, newDesc(f, m, l)); 1.84 + 1.85 + 1.86 +// 2.b.i 1.87 +f = 70; 1.88 +m = 24; 1.89 +l = 100; 1.90 + 1.91 +expect = (new Date(f, m-1, l)).toDateString(); 1.92 +actual = newDate(f, m, l).toDateString(); 1.93 +reportCompare(expect, actual, newDesc(f, m, l)); 1.94 + 1.95 +f = 99; 1.96 +m = 12; 1.97 +l = 1; 1.98 + 1.99 +expect = (new Date(f, m-1, l)).toDateString(); 1.100 +actual = newDate(f, m, l).toDateString(); 1.101 +reportCompare(expect, actual, newDesc(f, m, l)); 1.102 + 1.103 +// 2.b.ii. 1.104 + 1.105 +f = 99; 1.106 +m = 70; 1.107 +l = 1; 1.108 + 1.109 +expect = true; 1.110 +actual = isNaN(newDate(f, m, l)); 1.111 +reportCompare(expect, actual, newDesc(f, m, l) + ' is an invalid date'); 1.112 + 1.113 +// 2.c.i 1.114 + 1.115 +f = 100; 1.116 +m = 12; 1.117 +l = 1; 1.118 + 1.119 +expect = (new Date(f, m-1, l)).toDateString(); 1.120 +actual = newDate(f, m, l).toDateString(); 1.121 +reportCompare(expect, actual, newDesc(f, m, l)); 1.122 + 1.123 +// 2.c.ii 1.124 + 1.125 +f = 100; 1.126 +m = 70; 1.127 +l = 1; 1.128 + 1.129 +expect = true; 1.130 +actual = isNaN(newDate(f, m, l)); 1.131 +reportCompare(expect, actual, newDesc(f, m, l) + ' is an invalid date'); 1.132 + 1.133 +