Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Removed Date.js, see wv.util for replacements

Mike McGanne1da1d991239
diff --git a/etc/deploy/wv.js.json b/etc/deploy/wv.js.json
index a495b8b76..4c4f6ebc3 100644
--- a/etc/deploy/wv.js.json
+++ b/etc/deploy/wv.js.json
@@ -1,6 +1,4 @@
[
- "src/js/Date.js",
-
"src/js/component.js",
"src/js/registry.js",
"src/js/rubberBand.js",
diff --git a/src/index.html b/src/index.html
index 77cf23f08..f9ab6dbb3 100644
--- a/src/index.html
+++ b/src/index.html
@@ -113,8 +113,6 @@
<!-- link.prod --> <!-- <script type="text/javascript" src="js/wv.js?v=20131218215115174&mobile"></script> -->
- <!-- link.dev --> <script type="text/javascript" src="js/Date.js"></script>
-
<!-- link.dev --> <script type="text/javascript" src="js/component.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/registry.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/rubberBand.js"></script>
diff --git a/src/js/Date.js b/src/js/Date.js
deleted file mode 100644
index ecf46696f..000000000
--- a/src/js/Date.js
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * @module Date
- */
-
-/**
- * Date handling utilities.
- *
- * @class Date
- */
-(function() {
-
- var zeroPad = function(num, places) {
- var zero = places - num.toString().length + 1;
- return Array(+(zero > 0 && zero)).join("0") + num;
- };
-
- /**
- * Parses a UTC ISO 8601 date.
- *
- * @method parseISOString
- * @static
- *
- * @param dateAsString {string} The string must be in the form of
- * yyyy-MM-ddThh:mm:ss.sssZ. Only the year, month, and day are required and
- * the remaining string can be shortened. The Z to denote UTC is optional.
- *
- * @return {Date} converted string as a date object, throws an exception if
- * the string is invalid
- */
- Date.parseISOString = function(dateAsString) {
- var dateTimeArr = dateAsString.split(/T/);
-
- var yyyymmdd = dateTimeArr[0].split("-");
-
- // Parse elements of date and time
- var year = yyyymmdd[0];
- var month = yyyymmdd[1] - 1;
- var day = yyyymmdd[2];
-
- var hour = 0;
- var minute = 0;
- var second = 0;
- var millisecond = 0;
-
- // Use default of midnight if time is not specified
- if ( dateTimeArr.length > 1 ) {
- var hhmmss = dateTimeArr[1].split(/[:\.Z]/);
- var hour = hhmmss[0] || 0;
- var minute = hhmmss[1] || 0;
- var second = hhmmss[2] || 0;
- var millisecond = hhmmss[3] || 0;
- }
- var date = new Date(Date.UTC(year, month, day, hour, minute, second,
- millisecond));
- if ( isNaN(date.getTime()) ) {
- throw new Error("Invalid date: " + dateAsString);
- }
- return date;
- };
-
- /**
- * Compares this instance to a Date object and return an number indication
- * of their relative values.
- *
- * This method copied from datejs:
- * http://code.google.com/p/datejs/
- *
- * @method compareTo
- *
- * @param date {Date} Date object to compare.
- *
- * @returns {integer}
- * * 1 = this is greaterthan date.
- * * -1 = this is lessthan date.
- * * 0 = values are equal
- */
- Date.prototype.compareTo = function(date) {
- if (isNaN(this)) {
- throw new Error(this);
- }
- if (date instanceof Date && !isNaN(date)) {
- return (this > date) ? 1 : (this < date) ? -1 : 0;
- } else {
- throw new TypeError(date);
- }
- };
-
- /**
- * Sets UTC hours, minutes, seconds, and milliseconds to zero.
- *
- * @method clearUTCTime
- * @return {Date} same instance of this object.
- */
- Date.prototype.clearUTCTime = function() {
- this.setUTCHours(0);
- this.setUTCMinutes(0);
- this.setUTCSeconds(0);
- this.setUTCMilliseconds(0);
- return this;
- };
-
- /**
- * Creates a copy of this date object.
- *
- * @metohd clone
- * @return {Date} new instance of this object.
- */
- Date.prototype.clone = function() {
- return new Date(this.getTime());
- };
-
- /**
- * Converts to an ISO 8601 formatted string in UTC.
- *
- * This function provided by OpenLayers.
- *
- * @method toISOString
- * @return {String} In the form of yyyy-MM-ddThh:mm:ss.sssZ.
- */
-
- /**
- * Converts to an ISO 8601 formatted string in UTC without the time values.
- *
- * @method toISOStringDate
- * @return {String} In the form of yyyy-MM-dd.
- */
- Date.prototype.toISOStringDate = function() {
- return this.toISOString().split("T")[0];
- };
-
- Date.prototype.toISOStringTimeHM = function() {
- var time = this.toISOString().split("T")[1];
- var parts = time.split(".")[0].split(":");
- return parts[0] + ":" + parts[1];
- };
-
- Date.prototype.toTimestampUTC = function() {
- return this.toISOString().replace(/[-:TZ\.]/g, "");
- };
-
- Date.parseTimestampUTC = function(str) {
- var v = str.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})/);
- return new Date(Date.UTC(
- parseInt(v[1], 10),
- parseInt(v[2] - 1, 10),
- parseInt(v[3], 10),
- parseInt(v[4], 10),
- parseInt(v[5], 10),
- parseInt(v[6], 10),
- parseInt(v[7], 10)));
- };
-
-})();
-
diff --git a/src/js/Worldview.js b/src/js/Worldview.js
index 5d9b92b53..c65982baa 100644
--- a/src/js/Worldview.js
+++ b/src/js/Worldview.js
@@ -57,52 +57,6 @@
return obj;
};
- /**
- * Gets the current time or the value set by overrideNow. Use this
- * instead of the Date methods to allow debugging alternate "now" times.
- *
- * @method now
- * @static
- *
- * @return {Date} The current time or the value set by overrideNow.
- */
- ns.now = function() {
- return new Date();
- };
-
- /**
- * Gets the current day or the value set by overrideNow. Use this
- * instead of the Date methods to allow debugging alternate "now" times.
- *
- * @method today
- * @static
- *
- * @return {Date} The current time, or the vlaue set by overrideNow, with
- * the UTC hours, minutes, and seconds fields set to zero.
- */
- ns.today = function() {
- return new Date().clearUTCTime();
- };
-
- /**
- * Overrides the times returned by now() and today().
- *
- * @method overrideNow
- * @static
- *
- * @param {Date} Return this date object of now() and today() instead
- * of the current time.
- */
- ns.overrideNow = function(date) {
- var overrideToday = date.clone().clearUTCTime();
- ns.now = function() {
- return new Date(date.getTime());
- };
- ns.today = function() {
- return new Date(overrideToday.getTime());
- };
- };
-
/**
* Worldview general error handler. The error is reported to the browser
* console and, if the JavaScript library with YAHOO.widget.Panel is
diff --git a/src/js/Worldview/DataDownload/ECHO.js b/src/js/Worldview/DataDownload/ECHO.js
index e151754b5..e2b0ce3de 100644
--- a/src/js/Worldview/DataDownload/ECHO.js
+++ b/src/js/Worldview/DataDownload/ECHO.js
@@ -1,10 +1,10 @@
/*
* NASA Worldview
- *
+ *
* This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
+ * the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
@@ -12,21 +12,21 @@
Worldview.namespace("DataDownload");
Worldview.DataDownload.ECHO = function() {
-
+
var ns = {};
-
+
ns.REL_DATA = "http://esipfed.org/ns/fedsearch/1.1/data#";
ns.REL_BROWSE = "http://esipfed.org/ns/fedsearch/1.1/browse#";
-
+
ns.roundTime = function(timeString) {
- var time = Date.parseISOString(timeString);
+ var time = wv.util.parseTimestampUTC(timeString);
if ( time.getUTCMilliseconds() >= 500 ) {
- time.setUTCSeconds(time.getUTCSeconds() + 1);
+ time.setUTCSeconds(time.getUTCSeconds() + 1);
}
time.setUTCMilliseconds(0);
- return time.toISOString();
+ return time.toISOString();
};
-
+
return ns;
-
+
}();
diff --git a/src/js/Worldview/DataDownload/ECHO/Client.js b/src/js/Worldview/DataDownload/ECHO/Client.js
index a969f8989..d600a529d 100644
--- a/src/js/Worldview/DataDownload/ECHO/Client.js
+++ b/src/js/Worldview/DataDownload/ECHO/Client.js
@@ -58,8 +58,9 @@ Worldview.DataDownload.ECHO.Client = function(spec) {
23, 59 + endTimeDelta, 59
));
- queryParameters.data.startTime = startTime.toTimestampUTC();
- queryParameters.data.endTime = endTime.toTimestampUTC();
+ queryParameters.data.startTime =
+ wv.util.toCompactTimestamp(startTime);
+ queryParameters.data.endTime = wv.util.toCompactTimestamp(endTime);
}
var deferred = $.Deferred();
diff --git a/src/js/Worldview/DataDownload/ECHO/MockClient.js b/src/js/Worldview/DataDownload/ECHO/MockClient.js
index 9b1668927..ef5c73274 100644
--- a/src/js/Worldview/DataDownload/ECHO/MockClient.js
+++ b/src/js/Worldview/DataDownload/ECHO/MockClient.js
@@ -56,11 +56,11 @@ Worldview.DataDownload.ECHO.MockClient = function(suffix) {
var diffDays = (day - resultsDay) / (1000 * 60 * 60 * 24);
$.each(data.feed.entry, function(index, entry) {
- var timeStart = Date.parseISOString(entry.time_start);
+ var timeStart = wv.util.parseTimestampUTC(entry.time_start);
timeStart.setUTCDate(timeStart.getUTCDate() + diffDays);
entry.time_start = timeStart.toISOString();
- var timeEnd = Date.parseISOString(entry.time_end);
+ var timeEnd = wv.util.parseTimestampUTC(entry.time_end);
timeEnd.setUTCDate(timeEnd.getUTCDate() + diffDays);
entry.time_end = timeEnd.toISOString();
});
diff --git a/src/js/Worldview/DataDownload/Results/DateTimeLabel.js b/src/js/Worldview/DataDownload/Results/DateTimeLabel.js
index 4cb7c1978..1c8dfb733 100644
--- a/src/js/Worldview/DataDownload/Results/DateTimeLabel.js
+++ b/src/js/Worldview/DataDownload/Results/DateTimeLabel.js
@@ -1,10 +1,10 @@
/*
* NASA Worldview
- *
+ *
* This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
+ * the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
@@ -17,26 +17,26 @@ Worldview.namespace("DataDownload.Results");
Worldview.DataDownload.Results.DateTimeLabel = function(time) {
var self = {};
-
+
self.name = "DateTimeLabel";
-
+
self.process = function(meta, granule) {
- var timeStart = Date.parseISOString(granule.time_start);
-
+ var timeStart = wv.util.parseTimestampUTC(granule.time_start);
+
// Some granules may not have an end time
if ( granule.time_end ) {
- var timeEnd = Date.parseISOString(granule.time_end);
- granule.label = timeStart.toISOStringDate() + ": " +
- timeStart.toISOStringTimeHM() + "-" +
- timeEnd.toISOStringTimeHM();
+ var timeEnd = wv.util.parseTimestampUTC(granule.time_end);
+ granule.label = wv.util.toISOStringDate(timeStart) + ": " +
+ wv.util.toISOStringTimeHM(timeStart) + "-" +
+ wv.util.toISOStringTimeHM(timeEnd);
} else {
- granule.label = timeStart.toISOStringDate() + ": " +
- timeStart.toISOStringTimeHM();
+ granule.label = wv.util.toISOStringDate(timeStart) + ": " +
+ wv.util.toISOStringTimeHM(timeStart);
}
-
- return granule;
+
+ return granule;
};
return self;
-
+
};
\ No newline at end of file
diff --git a/src/js/Worldview/DataDownload/Results/MODISGridLabel.js b/src/js/Worldview/DataDownload/Results/MODISGridLabel.js
index ee7d6d985..d82a0c357 100644
--- a/src/js/Worldview/DataDownload/Results/MODISGridLabel.js
+++ b/src/js/Worldview/DataDownload/Results/MODISGridLabel.js
@@ -1,10 +1,10 @@
/*
* NASA Worldview
- *
+ *
* This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
+ * the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
@@ -17,21 +17,21 @@ Worldview.namespace("DataDownload.Results");
Worldview.DataDownload.Results.MODISGridLabel = function() {
var self = {};
-
+
self.name = "MODISGridLabel";
-
+
self.process = function(meta, granule) {
granule.label = "h" + granule.h + " - " + "v" + granule.v;
-
- var timeStart = Date.parseISOString(granule.time_start);
- var date = timeStart.toISOStringDate();
-
+
+ var timeStart = wv.util.parseTimestampUTC(granule.time_start);
+ var date = wv.util.toISOStringDate(timeStart);
+
granule.downloadLabel = date + ": h" + granule.h + "-" + granule.v;
-
+
return granule;
};
-
+
return self;
-
+
};
diff --git a/src/js/Worldview/DataDownload/Results/TimeFilter.js b/src/js/Worldview/DataDownload/Results/TimeFilter.js
index 49f4d26f9..999bd9c24 100644
--- a/src/js/Worldview/DataDownload/Results/TimeFilter.js
+++ b/src/js/Worldview/DataDownload/Results/TimeFilter.js
@@ -1,10 +1,10 @@
/*
* NASA Worldview
- *
+ *
* This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
+ * the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
@@ -19,31 +19,33 @@ Worldview.DataDownload.Results.TimeFilter = function(spec) {
var westZone = null;
var eastZone = null;
var maxDistance = null;
-
+
var self = {};
self.name = "TimeFilter";
-
+
var init = function() {
- westZone = spec.time.clone().setUTCMinutes(spec.westZone);
- eastZone = spec.time.clone().setUTCMinutes(spec.eastZone);
+ westZone = new Date(spec.time.getTime())
+ .setUTCMinutes(spec.westZone);
+ eastZone = new Date(spec.time.getTime())
+ .setUTCMinutes(spec.eastZone);
maxDistance = spec.maxDistance;
timeOffset = spec.timeOffset || 0;
};
-
+
self.process = function(meta, granule) {
var geom = granule.geometry[Worldview.Map.CRS_WGS_84];
- var time = Date.parseISOString(granule.time_start);
+ var time = wv.util.parseTimestampUTC(granule.time_start);
time.setUTCMinutes(time.getUTCMinutes() + timeOffset);
if ( !Worldview.Map.isPolygonValid(geom, maxDistance) ) {
var adjustSign = ( time < eastZone ) ? 1 : -1;
- geom =
+ geom =
Worldview.Map.adjustAntiMeridian(geom, adjustSign);
granule.geometry[Worldview.Map.CRS_WGS_84] = geom;
granule.centroid[Worldview.Map.CRS_WGS_84] = geom.getCentroid();
}
-
- var x = granule.centroid[Worldview.Map.CRS_WGS_84].x;
+
+ var x = granule.centroid[Worldview.Map.CRS_WGS_84].x;
if ( time < eastZone && x < 0 ) {
return;
}
@@ -52,7 +54,7 @@ Worldview.DataDownload.Results.TimeFilter = function(spec) {
}
return granule;
};
-
+
init();
return self;
-}
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/src/js/Worldview/DataDownload/Results/TimeLabel.js b/src/js/Worldview/DataDownload/Results/TimeLabel.js
index 85dd5d512..da1207e7c 100644
--- a/src/js/Worldview/DataDownload/Results/TimeLabel.js
+++ b/src/js/Worldview/DataDownload/Results/TimeLabel.js
@@ -1,10 +1,10 @@
/*
* NASA Worldview
- *
+ *
* This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
+ * the Earth Science Data and Information System (ESDIS) project.
*
- * Copyright (C) 2013 United States Government as represented by the
+ * Copyright (C) 2013 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*/
@@ -17,45 +17,45 @@ Worldview.namespace("DataDownload.Results");
Worldview.DataDownload.Results.TimeLabel = function(time) {
var self = {};
-
+
self.name = "TimeLabel";
-
+
self.process = function(meta, granule) {
- var timeStart = Date.parseISOString(granule.time_start);
-
+ var timeStart = wv.util.parseTimestampUTC(granule.time_start);
+
// Sometimes an end time is not provided by ECHO
var timeEnd;
if ( granule.time_end ) {
- timeEnd = Date.parseISOString(granule.time_end);
+ timeEnd = wv.util.parseTimestampUTC(granule.time_end);
}
-
+
var diff = Math.floor(
(timeStart.getTime() - time.getTime()) / (1000 * 60 * 60 * 24)
);
-
+
var suffix = "";
if ( diff !== 0 ) {
- if ( diff < 0 ) {
+ if ( diff < 0 ) {
suffix = " (" + diff + " day)";
} else {
suffix = " (+" + diff + " day)";
- }
+ }
}
- var displayStart = timeStart.toISOStringTimeHM();
+ var displayStart = wv.util.toISOStringTimeHM(timeStart);
var displayEnd = null;
if ( timeEnd ) {
- displayEnd = timeEnd.toISOStringTimeHM();
+ displayEnd = wv.util.toISOStringTimeHM(timeEnd);
} else {
displayEnd = "?";
}
- granule.label = displayStart + " - " + displayEnd + suffix;
-
- granule.downloadLabel = timeStart.toISOStringDate() + ": " +
+ granule.label = displayStart + " - " + displayEnd + suffix;
+
+ granule.downloadLabel = wv.util.toISOStringDate(timeStart) + ": " +
displayStart + "-" + displayEnd;
-
- return granule;
+
+ return granule;
};
return self;
-
+
};
\ No newline at end of file
diff --git a/src/js/Worldview/Map/DailyLayerSet.js b/src/js/Worldview/Map/DailyLayerSet.js
index 2c5cc20a0..2dfc41c50 100644
--- a/src/js/Worldview/Map/DailyLayerSet.js
+++ b/src/js/Worldview/Map/DailyLayerSet.js
@@ -69,7 +69,7 @@ Worldview.Map.DailyLayerSet = function(map, config) {
//-------------------------------------------------------------------------
var init = function() {
- self.setDay(Worldview.today());
+ self.setDay(wv.util.today());
map.events.register("movestart", self, invalidate);
map.events.register("zoomend", self, invalidate);
@@ -89,7 +89,7 @@ Worldview.Map.DailyLayerSet = function(map, config) {
if ( !d ) {
return;
}
- var ds = d.toISOStringDate();
+ var ds = wv.util.toISOStringDate(d);
if ( ds === currentDay ) {
return;
}
diff --git a/src/js/Worldview/Map/MapSet.js b/src/js/Worldview/Map/MapSet.js
index 5367d89ae..8aa0e821a 100644
--- a/src/js/Worldview/Map/MapSet.js
+++ b/src/js/Worldview/Map/MapSet.js
@@ -39,7 +39,7 @@ Worldview.Map.MapSet = function(containerId, mapConfig, component) {
var activeLayers = {};
// Display layers on the map for this day
- var currentDay = Worldview.today();
+ var currentDay = wv.util.today();
// The number of layers in the processing of loading. This is used
// to fire maploadstart and maploadend events.
diff --git a/src/js/Worldview/Widget/ArcticProjectionChangeNotification.js b/src/js/Worldview/Widget/ArcticProjectionChangeNotification.js
index 9d3c20b59..dc5db30c4 100644
--- a/src/js/Worldview/Widget/ArcticProjectionChangeNotification.js
+++ b/src/js/Worldview/Widget/ArcticProjectionChangeNotification.js
@@ -96,13 +96,13 @@ Worldview.Widget.ArcticProjectionChangeNotification = function(config, bank) {
var currentDay;
if ( query.time ) {
try {
- currentDay = Date.parseISOString(query.time);
+ currentDay = wv.util.parseDateUTC(query.time);
} catch ( error ) {
console.warn("Invalid time: " + query.time);
- currentDay = Worldview.today();
+ currentDay = wv.util.today();
}
} else {
- currentDay = Worldview.today();
+ currentDay = wv.util.today();
}
if ( currentDay < self.changeDate ) {
if ( REGISTRY.isLoadingQuery ) {
@@ -144,7 +144,7 @@ Worldview.Widget.ArcticProjectionChangeNotification = function(config, bank) {
});
dialog.setHeader("Notice");
var body = [
- "On " + self.changeDate.toISOStringDate() + " the polar ",
+ "On " + wv.util.toISOStringDate(self.changeDate) + " the polar ",
"projections changed as follows:" ,
"<br/><br/>",
"The <b>Arctic projection</b> changed from Arctic Polar ",
diff --git a/src/js/Worldview/Widget/CRS.js b/src/js/Worldview/Widget/CRS.js
index 35674cb4b..6f8828edc 100644
--- a/src/js/Worldview/Widget/CRS.js
+++ b/src/js/Worldview/Widget/CRS.js
@@ -40,13 +40,13 @@ Worldview.Widget.CRS = function(config) {
var time;
if ( query.time ) {
try {
- time = Date.parseISOString(query.time).clearUTCTime();
+ time = wv.util.parseDateUTC(query.time);
} catch ( error ) {
console.warn("Invalid time: " + query.time);
- time = Worldview.today();
+ time = wv.util.today();
}
} else {
- time = Worldview.today();
+ time = wv.util.today();
}
if ( query["switch"] === "geographic" ) {
projection = "4326";
diff --git a/src/js/Worldview/Widget/WorldviewMap.js b/src/js/Worldview/Widget/WorldviewMap.js
index f99a9204f..0a2c63964 100644
--- a/src/js/Worldview/Widget/WorldviewMap.js
+++ b/src/js/Worldview/Widget/WorldviewMap.js
@@ -179,7 +179,7 @@ Worldview.Widget.WorldviewMap = function(containerId, config) {
// Set default extent according to time of day:
// at 00:00 UTC, start at far eastern edge of map: "20.6015625,-46.546875,179.9296875,53.015625"
// at 23:00 UTC, start at far western edge of map: "-179.9296875,-46.546875,-20.6015625,53.015625"
- var curHour = Worldview.now().getUTCHours();
+ var curHour = wv.util.now().getUTCHours();
// For earlier hours when data is still being filled in, force a far eastern perspective
if (curHour < 3) {
diff --git a/src/js/Worldview/module.js b/src/js/Worldview/module.js
deleted file mode 100644
index cdeca0916..000000000
--- a/src/js/Worldview/module.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-/**
- * Worldview reference client for GIBS.
- *
- * @module Worldview
- * @main Worldview
- */
\ No newline at end of file
diff --git a/src/js/events.js b/src/js/events.js
index 5358011c6..5aef6234b 100644
--- a/src/js/events.js
+++ b/src/js/events.js
@@ -506,7 +506,7 @@ SOTE.widget.Events.toggleDescription = function(e) {
// if something needs to be loaded, wait for it. else, move on.
if(curDate.indexOf(meta[ind].date, curDate.length - meta[ind].date.length) === -1) {
- self.models.date.set(Date.parseISOString(meta[ind].date));
+ self.models.date.set(wv.util.parseDateUTC(meta[ind].date));
if ( currentMap.layersLoading ) {
currentMap.events.register("maploadend", currentMap, setEventProducts);
} else {
diff --git a/src/js/imageDownload.js b/src/js/imageDownload.js
index 656b2ea32..7bb7f5364 100644
--- a/src/js/imageDownload.js
+++ b/src/js/imageDownload.js
@@ -162,9 +162,9 @@ SOTE.widget.ImageDownload.prototype.updateComponent = function(qs){
$('#selImgFormat option[value=KMZ]').remove();
}
}
- var dTime = Date.parseISOString(time).clearUTCTime();
+ var dTime = wv.util.parseDateUTC(time);
//Julian date, padded with two zeros (to ensure the julian date is always in DDD format).
- var jStart = Date.parseISOString(dTime.getUTCFullYear() + "-01-01");
+ var jStart = wv.util.parseDateUTC(dTime.getUTCFullYear() + "-01-01");
var jDate = "00" + (1+Math.ceil((dTime.getTime() - jStart) / 86400000));
dlURL += "TIME="+dTime.getUTCFullYear()+(jDate).substr((jDate.length)-3);
diff --git a/src/js/legacy/wv.legacy.date.js b/src/js/legacy/wv.legacy.date.js
index 75b297475..132321781 100644
--- a/src/js/legacy/wv.legacy.date.js
+++ b/src/js/legacy/wv.legacy.date.js
@@ -52,14 +52,14 @@ wv.legacy.date = wv.legacy.date || function(model) {
self.parse = function(queryString, object) {
var timeString = Worldview.extractFromQuery("time", queryString);
if ( !timeString ) {
- object.time = Worldview.today();
+ object.time = wv.util.today();
} else {
try {
- object.time = Date.parseISOString(timeString).clearUTCTime();
+ object.time = wv.util.parseDateUTC(timeString);
} catch ( error ) {
console.warn("Invalid time: " + timeString + ", reason: " +
error);
- object.time = Worldview.today();
+ object.time = wv.util.today();
}
}
};
diff --git a/src/js/main.js b/src/js/main.js
index b005cbd62..7332d315f 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -265,7 +265,7 @@ $(function() {// Initialize "static" vars
// Allow the current day to be overridden
if ( config.parameters.now ) {
try {
- var now = Date.parseISOString(config.parameters.now);
+ var now = Date.parseTimestampUTC(config.parameters.now);
Worldview.overrideNow(now);
console.warn("Overriding now: " + now.toISOString());
} catch ( error ) {
diff --git a/src/js/util/wv.util.browser.js b/src/js/util/wv.util.browser.js
index 9be2dda32..ae270c577 100644
--- a/src/js/util/wv.util.browser.js
+++ b/src/js/util/wv.util.browser.js
@@ -334,6 +334,27 @@ if ( !String.prototype.startsWith ) {
})();
}
+/*
+ * String.endsWith
+ *
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
+ */
+if (!String.prototype.endsWith) {
+ (function() {
+ Object.defineProperty(String.prototype, 'endsWith', {
+ enumerable: false,
+ configurable: false,
+ writable: false,
+ value: function (searchString, position) {
+ position = position || this.length;
+ position = position - searchString.length;
+ var lastIndex = this.lastIndexOf(searchString);
+ return lastIndex !== -1 && lastIndex === position;
+ }
+ });
+ })();
+}
+
/*
* Mobile device quirks.
*/
diff --git a/src/js/util/wv.util.js b/src/js/util/wv.util.js
index 754e7a0ba..71bc4be4e 100644
--- a/src/js/util/wv.util.js
+++ b/src/js/util/wv.util.js
@@ -97,6 +97,26 @@ wv.util = (function(self) {
return "?" + parts.join("&");
};
+ /**
+ * Parses a UTC ISO 8601 timestamp.
+ *
+ * @method parseTimestampUTC
+ * @static
+ * @param str {String} Date to parse in the form of
+ * ``YYYY-MM-DDTHH:MM:SS.SSSZ``. Fractional seconds and the "Z"
+ * time zone desginator are optional.
+ * @return {Date} converted string as a datetime object, throws an
+ * exception if the string is invalid.
+ */
+ self.parseTimestampUTC = function(str) {
+ str = ( str.endsWith("Z") ) ? str : str + "Z";
+ var d = new Date(Date.parse(str));
+ if ( _.isNaN(d.getTime()) ) {
+ throw new Error("Invalid timestamp: " + str);
+ }
+ return d;
+ };
+
/**
* Parses a UTC ISO 8601 date.
*
@@ -126,6 +146,20 @@ wv.util = (function(self) {
return date.toISOString().split("T")[0];
};
+ /**
+ * Converts a time into an ISO string without seconds.
+ *
+ * @method toISOStringTimeHM
+ * @static
+ * @param date {Date} the date to convert
+ * @return {string} ISO string in the form of ``HH:MM``.
+ */
+ self.toISOStringTimeHM = function(date) {
+ var time = date.toISOString().split("T")[1];
+ var parts = time.split(".")[0].split(":");
+ return parts[0] + ":" + parts[1];
+ };
+
/**
* Sets a date to UTC midnight.
*
@@ -143,6 +177,43 @@ wv.util = (function(self) {
return date;
};
+ /**
+ * Converts a date into a compact string representation.
+ *
+ * @method toCompactTimestamp
+ * @static
+ * @param date {Date} the date to convert
+ * @return {String} string representation in the form of
+ * ``YYYYMMDDHHMMSSsss``
+ */
+ self.toCompactTimestamp = function(date) {
+ return date.toISOString().replace(/[-:TZ\.]/g, "");
+ };
+
+ /**
+ * Converts a compact timestamp into a date.
+ *
+ * @method fromCompactTimestamp
+ * @static
+ * @param str {String} the string to convert in the form of
+ * ``YYYYMMDDHHMMSSsss``.
+ * @return {Date} the converted date object.
+ */
+ self.fromCompactTimestamp = function(str) {
+ var v = str.match(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})/);
+ if ( _.isNull(v) ) {
+ throw new Error("Invalid timestamp:" + str);
+ }
+ return new Date(Date.UTC(
+ parseInt(v[1], 10),
+ parseInt(v[2] - 1, 10),
+ parseInt(v[3], 10),
+ parseInt(v[4], 10),
+ parseInt(v[5], 10),
+ parseInt(v[6], 10),
+ parseInt(v[7], 10)));
+ };
+
/**
* Gets the current time. Use this instead of the Date methods to allow
* debugging alternate "now" times.
diff --git a/test/util/wv.util-test.js b/test/util/wv.util-test.js
index c903a7beb..1b6a2bab0 100644
--- a/test/util/wv.util-test.js
+++ b/test/util/wv.util-test.js
@@ -56,14 +56,22 @@ buster.testCase("wv.util", {
buster.assert.equals(qs, "?format=/image/png/");
},
+ "parseTimestampUTC: Parses valid timestamp": function() {
+ var answer = new Date(Date.UTC(2013, 02, 15, 11, 22, 33));
+ var result = wv.util.parseTimestampUTC("2013-03-15T11:22:33Z");
+ buster.assert.equals(result.getTime(), answer.getTime());
+ },
+
+ "parseTimestampUTC: Parses valid timestamp without Z": function() {
+ var answer = new Date(Date.UTC(2013, 02, 15, 11, 22, 33));
+ var result = wv.util.parseTimestampUTC("2013-03-15T11:22:33");
+ buster.assert.equals(result.getTime(), answer.getTime());
+ },
+
"parseDateUTC: Parses valid date": function() {
- var d = wv.util.parseDateUTC("2013-03-15");
- buster.assert.equals(2013, d.getUTCFullYear());
- buster.assert.equals(2, d.getUTCMonth());
- buster.assert.equals(15, d.getUTCDate());
- buster.assert.equals(0, d.getUTCHours());
- buster.assert.equals(0, d.getUTCMinutes());
- buster.assert.equals(0, d.getUTCSeconds());
+ var answer = new Date(Date.UTC(2013, 02, 15));
+ var result = wv.util.parseDateUTC("2013-03-15");
+ buster.assert.equals(result.getTime(), answer.getTime());
},
"parseDateUTC: Exception on invalid date": function() {
@@ -77,6 +85,30 @@ buster.testCase("wv.util", {
buster.assert.equals(wv.util.toISOStringDate(d), "2013-01-15");
},
+ "toISOStringTimeHM: Converts time": function() {
+ var d = new Date(Date.UTC(2013, 0, 15, 11, 22, 33));
+ buster.assert.equals(wv.util.toISOStringTimeHM(d), "11:22");
+ },
+
+ "toCompactTimestamp: Converts timestamp": function() {
+ var d = new Date(Date.UTC(2013, 0, 15, 11, 22, 33, 444));
+ buster.assert.equals(wv.util.toCompactTimestamp(d),
+ "20130115112233444");
+ },
+
+ "fromCompactTimestamp: Parses timestamp": function() {
+ var answer = new Date(Date.UTC(2013, 0, 15, 11, 22, 33, 444));
+ var result = wv.util.fromCompactTimestamp("20130115112233444");
+ buster.assert.equals(answer.getTime(), result.getTime());
+ },
+
+ "fromCompactTimestamp: Throws exception when invalid": function() {
+ var answer = new Date(Date.UTC(2013, 0, 15, 11, 22, 33, 444));
+ buster.assert.exception(function() {
+ wv.util.fromCompactTimestamp("x0130115112233444");
+ });
+ },
+
"clearTimeUTC: Time set to UTC midnight": function() {
var d = new Date(2013, 02, 15, 12, 34, 56, 789);
wv.util.clearTimeUTC(d);