test/script/basic/date.js

changeset 3
da1e581c933b
child 7
5a1b0714df0e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/script/basic/date.js	Fri Dec 21 16:36:24 2012 -0400
     1.3 @@ -0,0 +1,101 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + * 
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + * 
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + * 
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + * 
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/**
    1.28 + * Basic checks for Date constructor.
    1.29 + * FIXME: add more checks
    1.30 + *
    1.31 + * @test
    1.32 + * @option -timezone=Asia/Calcutta
    1.33 + * @run
    1.34 + */
    1.35 +
    1.36 +// check arity of tricky functions
    1.37 +print("Date.length = " + Date.length);
    1.38 +print("Date.UTC.length = " + Date.UTC.length);
    1.39 +print("Date.prototype.setSeconds.length = " + Date.prototype.setSeconds.length);
    1.40 +print("Date.prototype.setUTCSeconds.length = " + Date.prototype.setUTCSeconds.length);
    1.41 +print("Date.prototype.setMinutes.length = " + Date.prototype.setMinutes.length);
    1.42 +print("Date.prototype.setUTCMinutes.length = " + Date.prototype.setUTCMinutes.length);
    1.43 +print("Date.prototype.setHours.length = " + Date.prototype.setHours.length);
    1.44 +print("Date.prototype.setUTCHours.length = " + Date.prototype.setUTCHours.length);
    1.45 +print("Date.prototype.setMonth.length = " + Date.prototype.setMonth.length);
    1.46 +print("Date.prototype.setUTCMonth.length = " + Date.prototype.setUTCMonth.length);
    1.47 +print("Date.prototype.setFullYear.length = " + Date.prototype.setFullYear.length);
    1.48 +print("Date.prototype.setUTCFullYear.length = " + Date.prototype.setUTCFullYear.length);
    1.49 +
    1.50 +function printDate(d) {
    1.51 +    print(d.getMinutes());
    1.52 +    print(d.getSeconds());
    1.53 +    print(d.getMilliseconds());
    1.54 +    print(d.getUTCDate());
    1.55 +    print(d.getUTCDay());
    1.56 +    print(d.getUTCMonth());
    1.57 +    print(d.getUTCFullYear());
    1.58 +    print(d.getUTCHours());
    1.59 +    print(d.getUTCMinutes());
    1.60 +    print(d.getUTCSeconds());
    1.61 +    print(d.getUTCMilliseconds());
    1.62 +    print(d.toISOString());
    1.63 +    print(d.toUTCString());
    1.64 +    print(d.toString());
    1.65 +    print(d.toLocaleString());
    1.66 +    print(d.toLocaleDateString());
    1.67 +    print(d.toLocaleTimeString());
    1.68 +    print(d.toDateString());
    1.69 +    print(d.toTimeString());
    1.70 +    print(d.toJSON());
    1.71 +}
    1.72 +
    1.73 +var d = new Date(2011, 4, 3, 17, 1, 1, 0);
    1.74 +printDate(d);
    1.75 +
    1.76 +d.setUTCMinutes(40, 34);
    1.77 +printDate(d);
    1.78 +
    1.79 +d = new Date(Date.UTC(2000, 10, 1, 1, 1, 1, 1));
    1.80 +printDate(d);
    1.81 +
    1.82 +d = new Date(0);
    1.83 +d.setFullYear(2012);
    1.84 +d.setMonth(1);
    1.85 +d.setDate(2);
    1.86 +d.setHours(3);
    1.87 +d.setMinutes(3);
    1.88 +d.setSeconds(4);
    1.89 +d.setMilliseconds(5);
    1.90 +printDate(d);
    1.91 +
    1.92 +d = new Date(0);
    1.93 +d.setUTCFullYear(2012);
    1.94 +d.setUTCMonth(1);
    1.95 +d.setUTCDate(2);
    1.96 +d.setUTCHours(3);
    1.97 +d.setUTCMinutes(4);
    1.98 +d.setUTCSeconds(5);
    1.99 +d.setUTCMilliseconds(6);
   1.100 +printDate(d);
   1.101 +
   1.102 +d = new Date(0);
   1.103 +d.setTime(1000);
   1.104 +printDate(d);

mercurial