• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15var d = new Date(1999, 1, 1);
16assert (d.getYear() === 99);
17d = new Date(1874, 4, 9);
18assert (d.getYear() === -26);
19d = new Date(2015, 8, 17);
20assert (d.getYear() === 115);
21d = new Date(NaN);
22assert (isNaN (d.getYear()));
23
24var d = new Date();
25d.setYear(91);
26assert (d.getFullYear() === 1991 && d.getYear() === 91);
27
28d = new Date();
29d.setYear(NaN);
30assert (isNaN(d.valueOf()));
31
32d = new Date();
33d.setYear(2015);
34assert (d.getFullYear() === 2015);
35
36d = new Date(2000, 1, 29);
37d.setYear(2004);
38assert (d.getFullYear() === 2004 && d.getMonth() === 1 && d.getDate() === 29);
39d.setYear(2015);
40assert (d.getFullYear() === 2015 && d.getMonth() === 2 && d.getDate() === 1);
41
42assert (/Thu, 17 Sep 2015 \d{2}:\d{2}:\d{2} GMT/.test (new Date("2015-09-17").toGMTString()));
43
44d = new Date(NaN);
45assert (d.toGMTString() === "Invalid Date");
46