Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Adjust `prevMonthInDateRange` +1 month & cache "0" month day correctly - Adjust prevMonthInDateRange function to correctly pull in layers within 1 month of the previous end date - Correctly cache the day when the currentDate is equal to the closest month's day.

ZachTRice63651025b99b
diff --git a/web/js/util/util.js b/web/js/util/util.js
index 64a88ed25..67a86d4fe 100644
--- a/web/js/util/util.js
+++ b/web/js/util/util.js
@@ -841,33 +841,34 @@ export default (function (self) {
// Offset timezone
minDate = new Date(minDate.getTime() + (minDate.getTimezoneOffset() * 60000));
maxDate = new Date(maxDate.getTime() + (maxDate.getTimezoneOffset() * 60000));
+ maxDate = new Date(maxDate.getUTCFullYear(), maxDate.getUTCMonth() + 1, maxDate.getUTCDate());
// Check if date is between dateRange.startDate && dateRange.endDate
if (currentDate >= minDate && currentDate <= maxDate) {
- // Find the monthDifference of the endDate vs startDate (i.e. 10)
+ // Find the monthDifference of the endDate vs startDate
monthDifference = self.monthDiff(minDate, maxDate);
}
// Create array of all possible request dates by saying for interval++ <= monthDifference
- for (dateInterval = 0; dateInterval <= monthDifference; dateInterval++) {
+ for (dateInterval = 0; dateInterval <= (monthDifference + 1); dateInterval++) {
dateArray.push(new Date(minDate.getUTCFullYear(), minDate.getUTCMonth() + dateInterval, minDate.getUTCDate(), 0, 0, 0));
}
});
-
// Find the closest dates within the current aray
dateArray.sort(function(a, b) {
var distancea = Math.abs(currentDate - a);
var distanceb = Math.abs(currentDate - b);
+
return distancea - distanceb; // sort a before b when the distance is smaller
});
// Filter the closest dates to only show dates before the currently selected date
var closestBeforeMonths = dateArray.filter(function(d) {
- return d - currentDate < 0;
+ return d - currentDate <= 0;
});
// Closest month, in date range, before current date = closestBeforeMonths[0]
- if (closestBeforeMonths[0]) {
+ if (closestBeforeMonths[0] && self.monthDiff(closestBeforeMonths[0], currentDate) <= 1) {
return closestBeforeMonths[0];
} else {
return date;