Browse Source

Added two date tests from SunSpider.

John Resig 16 years ago
parent
commit
1913ba212b
3 changed files with 743 additions and 0 deletions
  1. 16 0
      tests/MANIFEST.json
  2. 304 0
      tests/sunspider-date-format-tofte.js
  3. 423 0
      tests/sunspider-date-format-xparb.js

+ 16 - 0
tests/MANIFEST.json

@@ -199,6 +199,22 @@
 	category: "SunSpider JavaScript Tests",
 	tags: ["looping","string"]
 },
+"sunspider-date-format-xparb": {
+	file: "sunspider-date-format-xparb.js",
+	name: "Date Formatting",
+	origin: ["SunSpider", "http://www2.webkit.org/perf/sunspider-0.9/sunspider.html"],
+	desc: "Converting a date into a string representation.",
+	category: "SunSpider JavaScript Tests",
+	tags: ["date","string"]
+},
+"sunspider-date-format-tofte": {
+	file: "sunspider-date-format-tofte.js",
+	name: "Date Formatting (2)",
+	origin: ["SunSpider", "http://www2.webkit.org/perf/sunspider-0.9/sunspider.html"],
+	desc: "Converting a date into a string representation.",
+	category: "SunSpider JavaScript Tests",
+	tags: ["date","string"]
+},
 "sunspider-math-partial-sums": {
 	file: "sunspider-math-partial-sums.js",
 	name: "Partial Sum Calculation",

+ 304 - 0
tests/sunspider-date-format-tofte.js

@@ -0,0 +1,304 @@
+function arrayExists(array, x) {
+    for (var i = 0; i < array.length; i++) {
+        if (array[i] == x) return true;
+    }
+    return false;
+}
+
+Date.prototype.formatDate = function (input,time) {
+    // formatDate :
+    // a PHP date like function, for formatting date strings
+    // See: http://www.php.net/date
+    //
+    // input : format string
+    // time : epoch time (seconds, and optional)
+    //
+    // if time is not passed, formatting is based on 
+    // the current "this" date object's set time.
+    //
+    // supported:
+    // a, A, B, d, D, F, g, G, h, H, i, j, l (lowercase L), L, 
+    // m, M, n, O, r, s, S, t, U, w, W, y, Y, z
+    //
+    // unsupported:
+    // I (capital i), T, Z    
+
+    var switches =    ["a", "A", "B", "d", "D", "F", "g", "G", "h", "H", 
+                       "i", "j", "l", "L", "m", "M", "n", "O", "r", "s", 
+                       "S", "t", "U", "w", "W", "y", "Y", "z"];
+    var daysLong =    ["Sunday", "Monday", "Tuesday", "Wednesday", 
+                       "Thursday", "Friday", "Saturday"];
+    var daysShort =   ["Sun", "Mon", "Tue", "Wed", 
+                       "Thu", "Fri", "Sat"];
+    var monthsShort = ["Jan", "Feb", "Mar", "Apr",
+                       "May", "Jun", "Jul", "Aug", "Sep",
+                       "Oct", "Nov", "Dec"];
+    var monthsLong =  ["January", "February", "March", "April",
+                       "May", "June", "July", "August", "September",
+                       "October", "November", "December"];
+    var daysSuffix = ["st", "nd", "rd", "th", "th", "th", "th", // 1st - 7th
+                      "th", "th", "th", "th", "th", "th", "th", // 8th - 14th
+                      "th", "th", "th", "th", "th", "th", "st", // 15th - 21st
+                      "nd", "rd", "th", "th", "th", "th", "th", // 22nd - 28th
+                      "th", "th", "st"];                        // 29th - 31st
+
+    function a() {
+        // Lowercase Ante meridiem and Post meridiem
+        return self.getHours() > 11? "pm" : "am";
+    }
+    function A() {
+        // Uppercase Ante meridiem and Post meridiem
+        return self.getHours() > 11? "PM" : "AM";
+    }
+
+    function B(){
+        // Swatch internet time. code simply grabbed from ppk,
+        // since I was feeling lazy:
+        // http://www.xs4all.nl/~ppk/js/beat.html
+        var off = (self.getTimezoneOffset() + 60)*60;
+        var theSeconds = (self.getHours() * 3600) + 
+                         (self.getMinutes() * 60) + 
+                          self.getSeconds() + off;
+        var beat = Math.floor(theSeconds/86.4);
+        if (beat > 1000) beat -= 1000;
+        if (beat < 0) beat += 1000;
+        if ((""+beat).length == 1) beat = "00"+beat;
+        if ((""+beat).length == 2) beat = "0"+beat;
+        return beat;
+    }
+    
+    function d() {
+        // Day of the month, 2 digits with leading zeros
+        return new String(self.getDate()).length == 1?
+        "0"+self.getDate() : self.getDate();
+    }
+    function D() {
+        // A textual representation of a day, three letters
+        return daysShort[self.getDay()];
+    }
+    function F() {
+        // A full textual representation of a month
+        return monthsLong[self.getMonth()];
+    }
+    function g() {
+        // 12-hour format of an hour without leading zeros
+        return self.getHours() > 12? self.getHours()-12 : self.getHours();
+    }
+    function G() {
+        // 24-hour format of an hour without leading zeros
+        return self.getHours();
+    }
+    function h() {
+        // 12-hour format of an hour with leading zeros
+        if (self.getHours() > 12) {
+          var s = new String(self.getHours()-12);
+          return s.length == 1?
+          "0"+ (self.getHours()-12) : self.getHours()-12;
+        } else { 
+          var s = new String(self.getHours());
+          return s.length == 1?
+          "0"+self.getHours() : self.getHours();
+        }  
+    }
+    function H() {
+        // 24-hour format of an hour with leading zeros
+        return new String(self.getHours()).length == 1?
+        "0"+self.getHours() : self.getHours();
+    }
+    function i() {
+        // Minutes with leading zeros
+        return new String(self.getMinutes()).length == 1? 
+        "0"+self.getMinutes() : self.getMinutes(); 
+    }
+    function j() {
+        // Day of the month without leading zeros
+        return self.getDate();
+    }    
+    function l() {
+        // A full textual representation of the day of the week
+        return daysLong[self.getDay()];
+    }
+    function L() {
+        // leap year or not. 1 if leap year, 0 if not.
+        // the logic should match iso's 8601 standard.
+        var y_ = Y();
+        if (         
+            (y_ % 4 == 0 && y_ % 100 != 0) ||
+            (y_ % 4 == 0 && y_ % 100 == 0 && y_ % 400 == 0)
+            ) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+    function m() {
+        // Numeric representation of a month, with leading zeros
+        return self.getMonth() < 9?
+        "0"+(self.getMonth()+1) : 
+        self.getMonth()+1;
+    }
+    function M() {
+        // A short textual representation of a month, three letters
+        return monthsShort[self.getMonth()];
+    }
+    function n() {
+        // Numeric representation of a month, without leading zeros
+        return self.getMonth()+1;
+    }
+    function O() {
+        // Difference to Greenwich time (GMT) in hours
+        var os = Math.abs(self.getTimezoneOffset());
+        var h = ""+Math.floor(os/60);
+        var m = ""+(os%60);
+        h.length == 1? h = "0"+h:1;
+        m.length == 1? m = "0"+m:1;
+        return self.getTimezoneOffset() < 0 ? "+"+h+m : "-"+h+m;
+    }
+    function r() {
+        // RFC 822 formatted date
+        var r; // result
+        //  Thu    ,     21          Dec         2000
+        r = D() + ", " + j() + " " + M() + " " + Y() +
+        //        16     :    01     :    07          +0200
+            " " + H() + ":" + i() + ":" + s() + " " + O();
+        return r;
+    }
+    function S() {
+        // English ordinal suffix for the day of the month, 2 characters
+        return daysSuffix[self.getDate()-1];
+    }
+    function s() {
+        // Seconds, with leading zeros
+        return new String(self.getSeconds()).length == 1?
+        "0"+self.getSeconds() : self.getSeconds();
+    }
+    function t() {
+
+        // thanks to Matt Bannon for some much needed code-fixes here!
+        var daysinmonths = [null,31,28,31,30,31,30,31,31,30,31,30,31];
+        if (L()==1 && n()==2) return 29; // leap day
+        return daysinmonths[n()];
+    }
+    function U() {
+        // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
+        return Math.round(self.getTime()/1000);
+    }
+    function W() {
+        // Weeknumber, as per ISO specification:
+        // http://www.cl.cam.ac.uk/~mgk25/iso-time.html
+        
+        // if the day is three days before newyears eve,
+        // there's a chance it's "week 1" of next year.
+        // here we check for that.
+        var beforeNY = 364+L() - z();
+        var afterNY  = z();
+        var weekday = w()!=0?w()-1:6; // makes sunday (0), into 6.
+        if (beforeNY <= 2 && weekday <= 2-beforeNY) {
+            return 1;
+        }
+        // similarly, if the day is within threedays of newyears
+        // there's a chance it belongs in the old year.
+        var ny = new Date("January 1 " + Y() + " 00:00:00");
+        var nyDay = ny.getDay()!=0?ny.getDay()-1:6;
+        if (
+            (afterNY <= 2) && 
+            (nyDay >=4)  && 
+            (afterNY >= (6-nyDay))
+            ) {
+            // Since I'm not sure we can just always return 53,
+            // i call the function here again, using the last day
+            // of the previous year, as the date, and then just
+            // return that week.
+            var prevNY = new Date("December 31 " + (Y()-1) + " 00:00:00");
+            return prevNY.formatDate("W");
+        }
+        
+        // week 1, is the week that has the first thursday in it.
+        // note that this value is not zero index.
+        if (nyDay <= 3) {
+            // first day of the year fell on a thursday, or earlier.
+            return 1 + Math.floor( ( z() + nyDay ) / 7 );
+        } else {
+            // first day of the year fell on a friday, or later.
+            return 1 + Math.floor( ( z() - ( 7 - nyDay ) ) / 7 );
+        }
+    }
+    function w() {
+        // Numeric representation of the day of the week
+        return self.getDay();
+    }
+    
+    function Y() {
+        // A full numeric representation of a year, 4 digits
+
+        // we first check, if getFullYear is supported. if it
+        // is, we just use that. ppks code is nice, but wont
+        // work with dates outside 1900-2038, or something like that
+        if (self.getFullYear) {
+            var newDate = new Date("January 1 2001 00:00:00 +0000");
+            var x = newDate .getFullYear();
+            if (x == 2001) {              
+                // i trust the method now
+                return self.getFullYear();
+            }
+        }
+        // else, do this:
+        // codes thanks to ppk:
+        // http://www.xs4all.nl/~ppk/js/introdate.html
+        var x = self.getYear();
+        var y = x % 100;
+        y += (y < 38) ? 2000 : 1900;
+        return y;
+    }
+    function y() {
+        // A two-digit representation of a year
+        var y = Y()+"";
+        return y.substring(y.length-2,y.length);
+    }
+    function z() {
+        // The day of the year, zero indexed! 0 through 366
+        var t = new Date("January 1 " + Y() + " 00:00:00");
+        var diff = self.getTime() - t.getTime();
+        return Math.floor(diff/1000/60/60/24);
+    }
+        
+    var self = this;
+    if (time) {
+        // save time
+        var prevTime = self.getTime();
+        self.setTime(time);
+    }
+    
+    var ia = input.split("");
+    var ij = 0;
+    while (ia[ij]) {
+        if (ia[ij] == "\\") {
+            // this is our way of allowing users to escape stuff
+            ia.splice(ij,1);
+        } else {
+            if (arrayExists(switches,ia[ij])) {
+                ia[ij] = eval(ia[ij] + "()");
+            }
+        }
+        ij++;
+    }
+    // reset time, back to what it was
+    if (prevTime) {
+        self.setTime(prevTime);
+    }
+    return ia.join("");
+}
+
+var date = new Date("1/1/2007 1:11:11");
+
+startTest("sunspider-date-format-tofte");
+
+test("Format Date", function(){
+	for (i = 0; i < 50; ++i) {
+    		var shortFormat = date.formatDate("Y-m-d");
+    		var longFormat = date.formatDate("l, F d, Y g:i:s A");
+    		date.setTime(date.getTime() + 84266956);
+	}
+});
+
+endTest();

+ 423 - 0
tests/sunspider-date-format-xparb.js

@@ -0,0 +1,423 @@
+/*
+ * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, version 2.1.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+ * details.
+ */
+
+Date.parseFunctions = {count:0};
+Date.parseRegexes = [];
+Date.formatFunctions = {count:0};
+
+Date.prototype.dateFormat = function(format) {
+    if (Date.formatFunctions[format] == null) {
+        Date.createNewFormat(format);
+    }
+    var func = Date.formatFunctions[format];
+    return this[func]();
+}
+
+Date.createNewFormat = function(format) {
+    var funcName = "format" + Date.formatFunctions.count++;
+    Date.formatFunctions[format] = funcName;
+    var code = "Date.prototype." + funcName + " = function(){return ";
+    var special = false;
+    var ch = '';
+    for (var i = 0; i < format.length; ++i) {
+        ch = format.charAt(i);
+        if (!special && ch == "\\") {
+            special = true;
+        }
+        else if (special) {
+            special = false;
+            code += "'" + String.escape(ch) + "' + ";
+        }
+        else {
+            code += Date.getFormatCode(ch);
+        }
+    }
+    eval(code.substring(0, code.length - 3) + ";}");
+}
+
+Date.getFormatCode = function(character) {
+    switch (character) {
+    case "d":
+        return "String.leftPad(this.getDate(), 2, '0') + ";
+    case "D":
+        return "Date.dayNames[this.getDay()].substring(0, 3) + ";
+    case "j":
+        return "this.getDate() + ";
+    case "l":
+        return "Date.dayNames[this.getDay()] + ";
+    case "S":
+        return "this.getSuffix() + ";
+    case "w":
+        return "this.getDay() + ";
+    case "z":
+        return "this.getDayOfYear() + ";
+    case "W":
+        return "this.getWeekOfYear() + ";
+    case "F":
+        return "Date.monthNames[this.getMonth()] + ";
+    case "m":
+        return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
+    case "M":
+        return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
+    case "n":
+        return "(this.getMonth() + 1) + ";
+    case "t":
+        return "this.getDaysInMonth() + ";
+    case "L":
+        return "(this.isLeapYear() ? 1 : 0) + ";
+    case "Y":
+        return "this.getFullYear() + ";
+    case "y":
+        return "('' + this.getFullYear()).substring(2, 4) + ";
+    case "a":
+        return "(this.getHours() < 12 ? 'am' : 'pm') + ";
+    case "A":
+        return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
+    case "g":
+        return "((this.getHours() %12) ? this.getHours() % 12 : 12) + ";
+    case "G":
+        return "this.getHours() + ";
+    case "h":
+        return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";
+    case "H":
+        return "String.leftPad(this.getHours(), 2, '0') + ";
+    case "i":
+        return "String.leftPad(this.getMinutes(), 2, '0') + ";
+    case "s":
+        return "String.leftPad(this.getSeconds(), 2, '0') + ";
+    case "O":
+        return "this.getGMTOffset() + ";
+    case "T":
+        return "this.getTimezone() + ";
+    case "Z":
+        return "(this.getTimezoneOffset() * -60) + ";
+    default:
+        return "'" + String.escape(character) + "' + ";
+    }
+}
+
+Date.parseDate = function(input, format) {
+    if (Date.parseFunctions[format] == null) {
+        Date.createParser(format);
+    }
+    var func = Date.parseFunctions[format];
+    return Date[func](input);
+}
+
+Date.createParser = function(format) {
+    var funcName = "parse" + Date.parseFunctions.count++;
+    var regexNum = Date.parseRegexes.length;
+    var currentGroup = 1;
+    Date.parseFunctions[format] = funcName;
+
+    var code = "Date." + funcName + " = function(input){\n"
+        + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"
+        + "var d = new Date();\n"
+        + "y = d.getFullYear();\n"
+        + "m = d.getMonth();\n"
+        + "d = d.getDate();\n"
+        + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
+        + "if (results && results.length > 0) {"
+    var regex = "";
+
+    var special = false;
+    var ch = '';
+    for (var i = 0; i < format.length; ++i) {
+        ch = format.charAt(i);
+        if (!special && ch == "\\") {
+            special = true;
+        }
+        else if (special) {
+            special = false;
+            regex += String.escape(ch);
+        }
+        else {
+            obj = Date.formatCodeToRegex(ch, currentGroup);
+            currentGroup += obj.g;
+            regex += obj.s;
+            if (obj.g && obj.c) {
+                code += obj.c;
+            }
+        }
+    }
+
+    code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
+        + "{return new Date(y, m, d, h, i, s);}\n"
+        + "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
+        + "{return new Date(y, m, d, h, i);}\n"
+        + "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"
+        + "{return new Date(y, m, d, h);}\n"
+        + "else if (y > 0 && m >= 0 && d > 0)\n"
+        + "{return new Date(y, m, d);}\n"
+        + "else if (y > 0 && m >= 0)\n"
+        + "{return new Date(y, m);}\n"
+        + "else if (y > 0)\n"
+        + "{return new Date(y);}\n"
+        + "}return null;}";
+
+    Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
+    eval(code);
+}
+
+Date.formatCodeToRegex = function(character, currentGroup) {
+    switch (character) {
+    case "D":
+        return {g:0,
+        c:null,
+        s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
+    case "j":
+    case "d":
+        return {g:1,
+            c:"d = parseInt(results[" + currentGroup + "], 10);\n",
+            s:"(\\d{1,2})"};
+    case "l":
+        return {g:0,
+            c:null,
+            s:"(?:" + Date.dayNames.join("|") + ")"};
+    case "S":
+        return {g:0,
+            c:null,
+            s:"(?:st|nd|rd|th)"};
+    case "w":
+        return {g:0,
+            c:null,
+            s:"\\d"};
+    case "z":
+        return {g:0,
+            c:null,
+            s:"(?:\\d{1,3})"};
+    case "W":
+        return {g:0,
+            c:null,
+            s:"(?:\\d{2})"};
+    case "F":
+        return {g:1,
+            c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
+            s:"(" + Date.monthNames.join("|") + ")"};
+    case "M":
+        return {g:1,
+            c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
+            s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
+    case "n":
+    case "m":
+        return {g:1,
+            c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
+            s:"(\\d{1,2})"};
+    case "t":
+        return {g:0,
+            c:null,
+            s:"\\d{1,2}"};
+    case "L":
+        return {g:0,
+            c:null,
+            s:"(?:1|0)"};
+    case "Y":
+        return {g:1,
+            c:"y = parseInt(results[" + currentGroup + "], 10);\n",
+            s:"(\\d{4})"};
+    case "y":
+        return {g:1,
+            c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
+                + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
+            s:"(\\d{1,2})"};
+    case "a":
+        return {g:1,
+            c:"if (results[" + currentGroup + "] == 'am') {\n"
+                + "if (h == 12) { h = 0; }\n"
+                + "} else { if (h < 12) { h += 12; }}",
+            s:"(am|pm)"};
+    case "A":
+        return {g:1,
+            c:"if (results[" + currentGroup + "] == 'AM') {\n"
+                + "if (h == 12) { h = 0; }\n"
+                + "} else { if (h < 12) { h += 12; }}",
+            s:"(AM|PM)"};
+    case "g":
+    case "G":
+    case "h":
+    case "H":
+        return {g:1,
+            c:"h = parseInt(results[" + currentGroup + "], 10);\n",
+            s:"(\\d{1,2})"};
+    case "i":
+        return {g:1,
+            c:"i = parseInt(results[" + currentGroup + "], 10);\n",
+            s:"(\\d{2})"};
+    case "s":
+        return {g:1,
+            c:"s = parseInt(results[" + currentGroup + "], 10);\n",
+            s:"(\\d{2})"};
+    case "O":
+        return {g:0,
+            c:null,
+            s:"[+-]\\d{4}"};
+    case "T":
+        return {g:0,
+            c:null,
+            s:"[A-Z]{3}"};
+    case "Z":
+        return {g:0,
+            c:null,
+            s:"[+-]\\d{1,5}"};
+    default:
+        return {g:0,
+            c:null,
+            s:String.escape(character)};
+    }
+}
+
+Date.prototype.getTimezone = function() {
+    return this.toString().replace(
+        /^.*? ([A-Z]{3}) [0-9]{4}.*$/, "$1").replace(
+        /^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3");
+}
+
+Date.prototype.getGMTOffset = function() {
+    return (this.getTimezoneOffset() > 0 ? "-" : "+")
+        + String.leftPad(Math.floor(this.getTimezoneOffset() / 60), 2, "0")
+        + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
+}
+
+Date.prototype.getDayOfYear = function() {
+    var num = 0;
+    Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
+    for (var i = 0; i < this.getMonth(); ++i) {
+        num += Date.daysInMonth[i];
+    }
+    return num + this.getDate() - 1;
+}
+
+Date.prototype.getWeekOfYear = function() {
+    // Skip to Thursday of this week
+    var now = this.getDayOfYear() + (4 - this.getDay());
+    // Find the first Thursday of the year
+    var jan1 = new Date(this.getFullYear(), 0, 1);
+    var then = (7 - jan1.getDay() + 4);
+    document.write(then);
+    return String.leftPad(((now - then) / 7) + 1, 2, "0");
+}
+
+Date.prototype.isLeapYear = function() {
+    var year = this.getFullYear();
+    return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
+}
+
+Date.prototype.getFirstDayOfMonth = function() {
+    var day = (this.getDay() - (this.getDate() - 1)) % 7;
+    return (day < 0) ? (day + 7) : day;
+}
+
+Date.prototype.getLastDayOfMonth = function() {
+    var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
+    return (day < 0) ? (day + 7) : day;
+}
+
+Date.prototype.getDaysInMonth = function() {
+    Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
+    return Date.daysInMonth[this.getMonth()];
+}
+
+Date.prototype.getSuffix = function() {
+    switch (this.getDate()) {
+        case 1:
+        case 21:
+        case 31:
+            return "st";
+        case 2:
+        case 22:
+            return "nd";
+        case 3:
+        case 23:
+            return "rd";
+        default:
+            return "th";
+    }
+}
+
+String.escape = function(string) {
+    return string.replace(/('|\\)/g, "\\$1");
+}
+
+String.leftPad = function (val, size, ch) {
+    var result = new String(val);
+    if (ch == null) {
+        ch = " ";
+    }
+    while (result.length < size) {
+        result = ch + result;
+    }
+    return result;
+}
+
+Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
+Date.monthNames =
+   ["January",
+    "February",
+    "March",
+    "April",
+    "May",
+    "June",
+    "July",
+    "August",
+    "September",
+    "October",
+    "November",
+    "December"];
+Date.dayNames =
+   ["Sunday",
+    "Monday",
+    "Tuesday",
+    "Wednesday",
+    "Thursday",
+    "Friday",
+    "Saturday"];
+Date.y2kYear = 50;
+Date.monthNumbers = {
+    Jan:0,
+    Feb:1,
+    Mar:2,
+    Apr:3,
+    May:4,
+    Jun:5,
+    Jul:6,
+    Aug:7,
+    Sep:8,
+    Oct:9,
+    Nov:10,
+    Dec:11};
+Date.patterns = {
+    ISO8601LongPattern:"Y-m-d H:i:s",
+    ISO8601ShortPattern:"Y-m-d",
+    ShortDatePattern: "n/j/Y",
+    LongDatePattern: "l, F d, Y",
+    FullDateTimePattern: "l, F d, Y g:i:s A",
+    MonthDayPattern: "F d",
+    ShortTimePattern: "g:i A",
+    LongTimePattern: "g:i:s A",
+    SortableDateTimePattern: "Y-m-d\\TH:i:s",
+    UniversalSortableDateTimePattern: "Y-m-d H:i:sO",
+    YearMonthPattern: "F, Y"};
+
+var date = new Date("1/1/2007 1:11:11");
+
+startTest("sunspider-date-format-xparb");
+
+test("Date Format (2)", function(){
+	for (i = 0; i < 400; ++i) {
+    		var shortFormat = date.dateFormat("Y-m-d");
+    		var longFormat = date.dateFormat("l, F d, Y g:i:s A");
+    		date.setTime(date.getTime() + 84266956);
+	}
+});
+
+endTest();