michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 301738; michael@0: var summary = 'Date parse compatibilty with MSIE'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: /* michael@0: Case 2. The input string is of the form "f/m/l" where f, m and l are michael@0: integers, e.g. 7/16/45. michael@0: Adjust the mon, mday and year values to achieve 100% MSIE michael@0: compatibility. michael@0: a. If 0 <= f < 70, f/m/l is interpreted as month/day/year. michael@0: i. If year < 100, it is the number of years after 1900 michael@0: ii. If year >= 100, it is the number of years after 0. michael@0: b. If 70 <= f < 100 michael@0: i. If m < 70, f/m/l is interpreted as michael@0: year/month/day where year is the number of years after michael@0: 1900. michael@0: ii. If m >= 70, the date is invalid. michael@0: c. If f >= 100 michael@0: i. If m < 70, f/m/l is interpreted as michael@0: year/month/day where year is the number of years after 0. michael@0: ii. If m >= 70, the date is invalid. michael@0: */ michael@0: michael@0: var f; michael@0: var m; michael@0: var l; michael@0: michael@0: function newDate(f, m, l) michael@0: { michael@0: return new Date(f + '/' + m + '/' + l); michael@0: } michael@0: michael@0: function newDesc(f, m, l) michael@0: { michael@0: return f + '/' + m + '/' + l; michael@0: } michael@0: michael@0: // 2.a.i michael@0: f = 0; michael@0: m = 0; michael@0: l = 0; michael@0: michael@0: expect = (new Date(l, f-1, m)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: f = 0; michael@0: m = 0; michael@0: l = 100; michael@0: michael@0: expect = (new Date(l, f-1, m)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: // 2.a.ii michael@0: f = 0; michael@0: m = 24; michael@0: l = 100; michael@0: michael@0: expect = (new Date(l, f-1, m)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: f = 0; michael@0: m = 24; michael@0: l = 2100; michael@0: michael@0: expect = (new Date(l, f-1, m)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: michael@0: // 2.b.i michael@0: f = 70; michael@0: m = 24; michael@0: l = 100; michael@0: michael@0: expect = (new Date(f, m-1, l)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: f = 99; michael@0: m = 12; michael@0: l = 1; michael@0: michael@0: expect = (new Date(f, m-1, l)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: // 2.b.ii. michael@0: michael@0: f = 99; michael@0: m = 70; michael@0: l = 1; michael@0: michael@0: expect = true; michael@0: actual = isNaN(newDate(f, m, l)); michael@0: reportCompare(expect, actual, newDesc(f, m, l) + ' is an invalid date'); michael@0: michael@0: // 2.c.i michael@0: michael@0: f = 100; michael@0: m = 12; michael@0: l = 1; michael@0: michael@0: expect = (new Date(f, m-1, l)).toDateString(); michael@0: actual = newDate(f, m, l).toDateString(); michael@0: reportCompare(expect, actual, newDesc(f, m, l)); michael@0: michael@0: // 2.c.ii michael@0: michael@0: f = 100; michael@0: m = 70; michael@0: l = 1; michael@0: michael@0: expect = true; michael@0: actual = isNaN(newDate(f, m, l)); michael@0: reportCompare(expect, actual, newDesc(f, m, l) + ' is an invalid date'); michael@0: michael@0: