[OpenLayers-Commits] r12204 - trunk/openlayers/tests/BaseTypes

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Aug 3 10:39:57 EDT 2011


Author: fredj
Date: 2011-08-03 07:39:55 -0700 (Wed, 03 Aug 2011)
New Revision: 12204

Added:
   trunk/openlayers/tests/BaseTypes/Date.html
Log:
add missing tests/BaseTypes/Date.html (yes, again) (see #3440)

Added: trunk/openlayers/tests/BaseTypes/Date.html
===================================================================
--- trunk/openlayers/tests/BaseTypes/Date.html	                        (rev 0)
+++ trunk/openlayers/tests/BaseTypes/Date.html	2011-08-03 14:39:55 UTC (rev 12204)
@@ -0,0 +1,162 @@
+<html>
+<head>
+  <script src="../OLLoader.js"></script>
+  <script type="text/javascript">
+
+    function test_Date_toISOString(t) {
+        t.plan(3);
+    
+        var date, str;
+
+        // check valid date
+        date = new Date(Date.UTC(2010, 10, 27, 18, 19, 15, 123));
+        str = OpenLayers.Date.toISOString(date);
+        t.eq(str, "2010-11-27T18:19:15.123Z", "valid date");
+        
+        // check zero padding
+        date = new Date(Date.UTC(2010, 7, 7, 18, 9, 5, 12));
+        str = OpenLayers.Date.toISOString(date);
+        t.eq(str, "2010-08-07T18:09:05.012Z", "zero padding");
+        
+        // check invalid date
+        date = new Date("foo");
+        str = OpenLayers.Date.toISOString(date);
+        t.eq(str, "Invalid Date", "invalid date");
+
+    }
+    
+    function test_Date_parse(t) {
+        
+        t.plan(93);
+        
+        var cases = {
+            "2000": {
+                year: 2000,
+                month: 0,
+                date: 1
+            },
+            "2005-10": {
+                year: 2005,
+                month: 9,
+                date: 1
+            },
+            "1971-07-23": {
+                year: 1971,
+                month: 6,
+                date: 23
+            },
+            "1801-11-20T04:30:15Z": {
+                year: 1801,
+                month: 10,
+                date: 20,
+                hour: 4,
+                minutes: 30,
+                seconds: 15
+            },
+            "1989-06-15T18:30:15.91Z": {
+                year: 1989,
+                month: 5,
+                date: 15,
+                hour: 18,
+                minutes: 30,
+                seconds: 15,
+                milliseconds: 910
+            },
+            "1989-06-15T18:30:15.091Z": {
+                year: 1989,
+                month: 5,
+                date: 15,
+                hour: 18,
+                minutes: 30,
+                seconds: 15,
+                milliseconds: 91
+            },
+            "1989-06-15T13:30:15.091-05": {
+                year: 1989,
+                month: 5,
+                date: 15,
+                hour: 18,
+                minutes: 30,
+                seconds: 15,
+                milliseconds: 91
+            },
+            "2010-08-06T15:21:25-06": { // MDT
+                year: 2010,
+                month: 7,
+                date: 6,
+                hour: 21,
+                minutes: 21,
+                seconds: 25
+            },
+            "2010-08-07T06:21:25+9": { // JSP
+                year: 2010,
+                month: 7,
+                date: 6,
+                hour: 21,
+                minutes: 21,
+                seconds: 25
+            },
+            "2010-08-07T02:51:25+05:30": { // IST
+                year: 2010,
+                month: 7,
+                date: 6,
+                hour: 21,
+                minutes: 21,
+                seconds: 25
+            },
+            "T21:51:25Z": {
+                hour: 21,
+                minutes: 51,
+                seconds: 25
+            },
+            "T02:51:25+05:30": { // IST
+                hour: 21,
+                minutes: 21,
+                seconds: 25
+            },
+            "T2:51:25.1234-7": { // lenient
+                hour: 9,
+                minutes: 51,
+                seconds: 25,
+                milliseconds: 123
+            }
+        };
+
+        var o, got, exp;
+        for (var str in cases) {
+            o = cases[str];
+            got = OpenLayers.Date.parse(str);
+            exp = new Date(Date.UTC(o.year || 0, o.month || 0, o.date || 1, o.hour || 0, o.minutes || 0, o.seconds || 0, o.milliseconds || 0));
+            if ("year" in o) {
+                t.eq(got.getUTCFullYear(), exp.getUTCFullYear(), str + ": correct UTCFullYear");
+                t.eq(got.getUTCMonth(), exp.getUTCMonth(), str + ": correct UTCMonth");
+                t.eq(got.getUTCDate(), exp.getUTCDate(), str + ": correct UTCDate");
+            } else {
+                t.ok(true, str + ": ECMA doesn't specify how years are handled in time only strings");
+                t.ok(true, str + ": ECMA doesn't specify how months are handled in time only strings");
+                t.ok(true, str + ": ECMA doesn't specify how days are handled in time only strings");
+            }
+            if ("hour" in o) {
+                t.eq(got.getUTCHours(), exp.getUTCHours(), str + ": correct UTCHours");
+                t.eq(got.getUTCMinutes(), exp.getUTCMinutes(), str + ": correct UTCMinutes");
+                t.eq(got.getUTCSeconds(), exp.getUTCSeconds(), str + ": correct UTCSeconds");
+                t.eq(got.getUTCMilliseconds(), exp.getUTCMilliseconds(), str + ": correct UTCMilliseconds");
+            } else {
+                t.ok(true, str + ": ECMA doesn't specify how hours are handled in date only strings");
+                t.ok(true, str + ": ECMA doesn't specify how minutes are handled in date only strings");
+                t.ok(true, str + ": ECMA doesn't specify how seconds are handled in date only strings");
+                t.ok(true, str + ": ECMA doesn't specify how milliseconds are handled in date only strings");
+            }
+        }
+        
+        // check invalid date parsing
+        var invalid = OpenLayers.Date.parse("foo");
+        t.ok(invalid instanceof Date, "invalid is a date");
+        t.ok(isNaN(invalid.getTime()), "invalid has no time");
+    }
+
+  </script>
+</head>
+<body>
+</body>
+</html>



More information about the Commits mailing list