[OpenLayers-Commits] r12202 - in trunk/openlayers: apidoc_config
doc_config lib lib/OpenLayers lib/OpenLayers/Format tests
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Aug 3 10:32:11 EDT 2011
Author: fredj
Date: 2011-08-03 07:32:10 -0700 (Wed, 03 Aug 2011)
New Revision: 12202
Modified:
trunk/openlayers/apidoc_config/Menu.txt
trunk/openlayers/doc_config/Menu.txt
trunk/openlayers/lib/OpenLayers.js
trunk/openlayers/lib/OpenLayers/BaseTypes.js
trunk/openlayers/lib/OpenLayers/Format/KML.js
trunk/openlayers/tests/BaseTypes.html
trunk/openlayers/tests/list-tests.html
Log:
move the OpenLayers.Date.* from BaseTypes.js to BaseTypes/Date.js. r=erilem (closes #3440)
Modified: trunk/openlayers/apidoc_config/Menu.txt
===================================================================
--- trunk/openlayers/apidoc_config/Menu.txt 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/apidoc_config/Menu.txt 2011-08-03 14:32:10 UTC (rev 12202)
@@ -55,6 +55,7 @@
File: Base Types (no auto-title, OpenLayers/BaseTypes.js)
File: Bounds (no auto-title, OpenLayers/BaseTypes/Bounds.js)
File: Class (no auto-title, OpenLayers/BaseTypes/Class.js)
+ File: Date (no auto-title, OpenLayers/BaseTypes/Date.js)
File: Element (no auto-title, OpenLayers/BaseTypes/Element.js)
File: LonLat (no auto-title, OpenLayers/BaseTypes/LonLat.js)
File: Pixel (no auto-title, OpenLayers/BaseTypes/Pixel.js)
Modified: trunk/openlayers/doc_config/Menu.txt
===================================================================
--- trunk/openlayers/doc_config/Menu.txt 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/doc_config/Menu.txt 2011-08-03 14:32:10 UTC (rev 12202)
@@ -55,6 +55,7 @@
File: Base Types (no auto-title, OpenLayers/BaseTypes.js)
File: Bounds (no auto-title, OpenLayers/BaseTypes/Bounds.js)
File: Class (no auto-title, OpenLayers/BaseTypes/Class.js)
+ File: Date (no auto-title, OpenLayers/BaseTypes/Date.js)
File: Element (no auto-title, OpenLayers/BaseTypes/Element.js)
File: LonLat (no auto-title, OpenLayers/BaseTypes/LonLat.js)
File: Pixel (no auto-title, OpenLayers/BaseTypes/Pixel.js)
Modified: trunk/openlayers/lib/OpenLayers/BaseTypes.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/BaseTypes.js 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/lib/OpenLayers/BaseTypes.js 2011-08-03 14:32:10 UTC (rev 12202)
@@ -564,118 +564,3 @@
}
};
-
-/**
- * Namespace: OpenLayers.Date
- * Contains implementations of Date.parse and date.toISOString that match the
- * ECMAScript 5 specification for parsing RFC 3339 dates.
- * http://tools.ietf.org/html/rfc3339
- */
-OpenLayers.Date = {
-
- /**
- * APIMethod: toISOString
- * Generates a string representing a date. The format of the string follows
- * the profile of ISO 8601 for date and time on the Internet (see
- * http://tools.ietf.org/html/rfc3339). If the toISOString method is
- * available on the Date prototype, that is used. The toISOString
- * method for Date instances is defined in ECMA-262.
- *
- * Parameters:
- * date - {Date} A date object.
- *
- * Returns:
- * {String} A string representing the date (e.g.
- * "2010-08-07T16:58:23.123Z"). If the date does not have a valid time
- * (i.e. isNaN(date.getTime())) this method returns the string "Invalid
- * Date". The ECMA standard says the toISOString method should throw
- * RangeError in this case, but Firefox returns a string instead. For
- * best results, use isNaN(date.getTime()) to determine date validity
- * before generating date strings.
- */
- toISOString: (function() {
- if ("toISOString" in Date.prototype) {
- return function(date) {
- return date.toISOString();
- };
- } else {
- function pad(num, len) {
- var str = num + "";
- while (str.length < len) {
- str = "0" + str;
- }
- return str;
- }
- return function(date) {
- var str;
- if (isNaN(date.getTime())) {
- // ECMA-262 says throw RangeError, Firefox returns
- // "Invalid Date"
- str = "Invalid Date";
- } else {
- str =
- date.getUTCFullYear() + "-" +
- pad(date.getUTCMonth() + 1, 2) + "-" +
- pad(date.getUTCDate(), 2) + "T" +
- pad(date.getUTCHours(), 2) + ":" +
- pad(date.getUTCMinutes(), 2) + ":" +
- pad(date.getUTCSeconds(), 2) + "." +
- pad(date.getUTCMilliseconds(), 3) + "Z";
- }
- return str;
- };
- }
-
- })(),
-
- /**
- * APIMethod: parse
- * Generate a date object from a string. The format for the string follows
- * the profile of ISO 8601 for date and time on the Internet (see
- * http://tools.ietf.org/html/rfc3339). We don't call the native
- * Date.parse because of inconsistency between implmentations. In
- * Chrome, calling Date.parse with a string that doesn't contain any
- * indication of the timezone (e.g. "2011"), the date is interpreted
- * in local time. On Firefox, the assumption is UTC.
- *
- * Parameters:
- * str - {String} A string representing the date (e.g.
- * "2010", "2010-08", "2010-08-07", "2010-08-07T16:58:23.123Z",
- * "2010-08-07T11:58:23.123-06").
- *
- * Returns:
- * {Date} A date object. If the string could not be parsed, an invalid
- * date is returned (i.e. isNaN(date.getTime())).
- */
- parse: function(str) {
- var date;
- var match = str.match(/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))?$/);
- if (match && (match[1] || match[7])) { // must have at least year or time
- var year = parseInt(match[1], 10) || 0;
- var month = (parseInt(match[2], 10) - 1) || 0;
- var day = parseInt(match[3], 10) || 1;
- date = new Date(Date.UTC(year, month, day));
- // optional time
- var type = match[7];
- if (type) {
- var hours = parseInt(match[4], 10);
- var minutes = parseInt(match[5], 10);
- var secFrac = parseFloat(match[6]);
- var seconds = secFrac | 0;
- var milliseconds = Math.round(1000 * (secFrac - seconds));
- date.setUTCHours(hours, minutes, seconds, milliseconds);
- // check offset
- if (type !== "Z") {
- var hoursOffset = parseInt(type, 10);
- var minutesOffset = parseInt(match[8], 10) || 0;
- var offset = -1000 * (60 * (hoursOffset * 60) + minutesOffset * 60);
- date = new Date(date.getTime() + offset);
- }
- }
- } else {
- date = new Date("invalid");
- }
- return date;
- }
-
-};
Modified: trunk/openlayers/lib/OpenLayers/Format/KML.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/KML.js 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/lib/OpenLayers/Format/KML.js 2011-08-03 14:32:10 UTC (rev 12202)
@@ -4,6 +4,7 @@
* full text of the license. */
/**
+ * @requires OpenLayers/BaseTypes/Date.js
* @requires OpenLayers/Format/XML.js
* @requires OpenLayers/Feature/Vector.js
* @requires OpenLayers/Geometry/Point.js
Modified: trunk/openlayers/lib/OpenLayers.js
===================================================================
--- trunk/openlayers/lib/OpenLayers.js 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/lib/OpenLayers.js 2011-08-03 14:32:10 UTC (rev 12202)
@@ -99,6 +99,7 @@
"OpenLayers/Util.js",
"OpenLayers/BaseTypes.js",
"OpenLayers/BaseTypes/Bounds.js",
+ "OpenLayers/BaseTypes/Date.js",
"OpenLayers/BaseTypes/Element.js",
"OpenLayers/BaseTypes/LonLat.js",
"OpenLayers/BaseTypes/Pixel.js",
Modified: trunk/openlayers/tests/BaseTypes.html
===================================================================
--- trunk/openlayers/tests/BaseTypes.html 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/tests/BaseTypes.html 2011-08-03 14:32:10 UTC (rev 12202)
@@ -364,160 +364,6 @@
}
- 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>
Modified: trunk/openlayers/tests/list-tests.html
===================================================================
--- trunk/openlayers/tests/list-tests.html 2011-07-29 14:00:39 UTC (rev 12201)
+++ trunk/openlayers/tests/list-tests.html 2011-08-03 14:32:10 UTC (rev 12202)
@@ -3,6 +3,7 @@
<li>BaseTypes.html</li>
<li>BaseTypes/Bounds.html</li>
<li>BaseTypes/Class.html</li>
+ <li>BaseTypes/Date.html</li>
<li>BaseTypes/Element.html</li>
<li>BaseTypes/LonLat.html</li>
<li>BaseTypes/Pixel.html</li>
More information about the Commits
mailing list