瀏覽代碼

fix prev/next range calculation

Adam Shaw 9 年之前
父節點
當前提交
4a84c92f73
共有 2 個文件被更改,包括 17 次插入6 次删除
  1. 8 6
      src/common/View.date-range.js
  2. 9 0
      src/util.js

+ 8 - 6
src/common/View.date-range.js

@@ -89,23 +89,25 @@ View.mixin({
 	// from its previous value. decremented = -1, incremented = 1 (default).
 	buildRangeInfo: function(date, direction) {
 		var validRange = this.buildValidRange();
-		var isDateValid = isDateWithinRange(date, validRange);
 		var currentInfo;
 		var renderRange;
 		var activeRange;
-		var isVisibleRangeValid;
+		var isActiveRangeValid;
 
-		date = constrainDate(date, validRange);
 		currentInfo = this.buildCurrentRangeInfo(date, direction);
 		renderRange = this.buildRenderRange(currentInfo.range, currentInfo.unit);
-		activeRange = constrainRange(renderRange, validRange);
+		activeRange = cloneRange(renderRange);
 
 		if (this.opt('disableNonCurrentDates')) {
 			activeRange = constrainRange(activeRange, currentInfo.range);
 		}
 
+		isActiveRangeValid = doRangesIntersect(activeRange, validRange);
+		if (isActiveRangeValid) {
+			activeRange = constrainRange(activeRange, validRange);
+		}
+
 		date = constrainDate(date, activeRange);
-		isVisibleRangeValid = Boolean(intersectRanges(activeRange, currentInfo.range));
 
 		return {
 			validRange: validRange,
@@ -113,7 +115,7 @@ View.mixin({
 			currentRangeUnit: currentInfo.unit,
 			activeRange: activeRange,
 			renderRange: renderRange,
-			isValid: isDateValid && isVisibleRangeValid,
+			isValid: isActiveRangeValid,
 			date: date,
 			dateIncrement: this.buildDateIncrement(currentInfo.duration)
 				// pass a fallback (might be null) ^

+ 9 - 0
src/util.js

@@ -696,6 +696,7 @@ function constrainRange(innerRange, outerRange) {
 
 
 // If the given date is not within the given range, move it inside.
+// (If it's past the end, make it one millisecond before the end).
 // Always returns a new moment.
 function constrainDate(date, range) {
 	date = date.clone();
@@ -718,6 +719,14 @@ function isDateWithinRange(date, range) {
 }
 
 
+// TODO: deal with repeat code in intersectRanges
+// constraintRange can have unspecified start/end, an open-ended range.
+function doRangesIntersect(subjectRange, constraintRange) {
+	return (!constraintRange.start || subjectRange.end >= constraintRange.start) &&
+		(!constrainRange.end || subjectRange.start < constrainRange.end);
+}
+
+
 function isRangeWithinRange(innerRange, outerRange) {
 	return (!outerRange.start || innerRange.start >= outerRange.start) &&
 		(!outerRange.end || innerRange.end <= outerRange.end);