test/script/basic/date.js

Sun, 08 Nov 2015 10:25:46 -0800

author
asaha
date
Sun, 08 Nov 2015 10:25:46 -0800
changeset 1687
6abfa80b9ef2
parent 962
ac62e33a99b0
child 1205
4112748288bb
permissions
-rw-r--r--

Added tag jdk8u66-b18 for changeset 39bfb9eb75dc

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation.
attila@962 8 *
jlaskey@3 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 12 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 13 * accompanied this code).
attila@962 14 *
jlaskey@3 15 * You should have received a copy of the GNU General Public License version
jlaskey@3 16 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
jlaskey@3 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 20 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 21 * questions.
jlaskey@3 22 */
jlaskey@3 23
jlaskey@3 24 /**
jlaskey@3 25 * Basic checks for Date constructor.
jlaskey@3 26 * FIXME: add more checks
jlaskey@3 27 *
jlaskey@3 28 * @test
jlaskey@3 29 * @option -timezone=Asia/Calcutta
jlaskey@3 30 * @run
jlaskey@3 31 */
jlaskey@3 32
jlaskey@3 33 // check arity of tricky functions
jlaskey@3 34 print("Date.length = " + Date.length);
jlaskey@3 35 print("Date.UTC.length = " + Date.UTC.length);
jlaskey@3 36 print("Date.prototype.setSeconds.length = " + Date.prototype.setSeconds.length);
jlaskey@3 37 print("Date.prototype.setUTCSeconds.length = " + Date.prototype.setUTCSeconds.length);
jlaskey@3 38 print("Date.prototype.setMinutes.length = " + Date.prototype.setMinutes.length);
jlaskey@3 39 print("Date.prototype.setUTCMinutes.length = " + Date.prototype.setUTCMinutes.length);
jlaskey@3 40 print("Date.prototype.setHours.length = " + Date.prototype.setHours.length);
jlaskey@3 41 print("Date.prototype.setUTCHours.length = " + Date.prototype.setUTCHours.length);
jlaskey@3 42 print("Date.prototype.setMonth.length = " + Date.prototype.setMonth.length);
jlaskey@3 43 print("Date.prototype.setUTCMonth.length = " + Date.prototype.setUTCMonth.length);
jlaskey@3 44 print("Date.prototype.setFullYear.length = " + Date.prototype.setFullYear.length);
jlaskey@3 45 print("Date.prototype.setUTCFullYear.length = " + Date.prototype.setUTCFullYear.length);
jlaskey@3 46
jlaskey@3 47 function printDate(d) {
jlaskey@3 48 print(d.getMinutes());
jlaskey@3 49 print(d.getSeconds());
jlaskey@3 50 print(d.getMilliseconds());
jlaskey@3 51 print(d.getUTCDate());
jlaskey@3 52 print(d.getUTCDay());
jlaskey@3 53 print(d.getUTCMonth());
jlaskey@3 54 print(d.getUTCFullYear());
jlaskey@3 55 print(d.getUTCHours());
jlaskey@3 56 print(d.getUTCMinutes());
jlaskey@3 57 print(d.getUTCSeconds());
jlaskey@3 58 print(d.getUTCMilliseconds());
jlaskey@3 59 print(d.toISOString());
jlaskey@3 60 print(d.toUTCString());
jlaskey@3 61 print(d.toString());
jlaskey@3 62 print(d.toLocaleString());
jlaskey@3 63 print(d.toLocaleDateString());
jlaskey@3 64 print(d.toLocaleTimeString());
jlaskey@3 65 print(d.toDateString());
jlaskey@3 66 print(d.toTimeString());
jlaskey@3 67 print(d.toJSON());
jlaskey@3 68 }
jlaskey@3 69
jlaskey@3 70 var d = new Date(2011, 4, 3, 17, 1, 1, 0);
jlaskey@3 71 printDate(d);
jlaskey@3 72
jlaskey@3 73 d.setUTCMinutes(40, 34);
jlaskey@3 74 printDate(d);
jlaskey@3 75
jlaskey@3 76 d = new Date(Date.UTC(2000, 10, 1, 1, 1, 1, 1));
jlaskey@3 77 printDate(d);
jlaskey@3 78
jlaskey@3 79 d = new Date(0);
jlaskey@3 80 d.setFullYear(2012);
jlaskey@3 81 d.setMonth(1);
jlaskey@3 82 d.setDate(2);
jlaskey@3 83 d.setHours(3);
jlaskey@3 84 d.setMinutes(3);
jlaskey@3 85 d.setSeconds(4);
jlaskey@3 86 d.setMilliseconds(5);
jlaskey@3 87 printDate(d);
jlaskey@3 88
jlaskey@3 89 d = new Date(0);
jlaskey@3 90 d.setUTCFullYear(2012);
jlaskey@3 91 d.setUTCMonth(1);
jlaskey@3 92 d.setUTCDate(2);
jlaskey@3 93 d.setUTCHours(3);
jlaskey@3 94 d.setUTCMinutes(4);
jlaskey@3 95 d.setUTCSeconds(5);
jlaskey@3 96 d.setUTCMilliseconds(6);
jlaskey@3 97 printDate(d);
jlaskey@3 98
jlaskey@3 99 d = new Date(0);
jlaskey@3 100 d.setTime(1000);
jlaskey@3 101 printDate(d);

mercurial