Răsfoiți Sursa

incompatibility between FC versions >= 2.2.5 and Moment versions <= 2.8.3

Adam Shaw 11 ani în urmă
părinte
comite
9ec97e2d16
3 a modificat fișierele cu 15 adăugiri și 41 ștergeri
  1. 1 1
      src/Calendar.js
  2. 1 1
      src/common/View.js
  3. 13 39
      src/util.js

+ 1 - 1
src/Calendar.js

@@ -436,7 +436,7 @@ function Calendar(element, instanceOptions) {
 			if (duration) {
 				duration = moment.duration(duration);
 				unit = computeIntervalUnit(duration);
-				unitIsSingle = computeIntervalAs(unit, duration) === 1;
+				unitIsSingle = duration.as(unit) === 1;
 			}
 
 			// options that are specified per the view's duration, like "week" or "day"

+ 1 - 1
src/common/View.js

@@ -124,7 +124,7 @@ var View = fc.View = Class.extend({
 		var start, end;
 
 		// normalize the range's time-ambiguity
-		if (computeIntervalAs('days', intervalDuration)) { // whole-days?
+		if (/year|month|week|day/.test(intervalUnit)) { // whole-days?
 			intervalStart.stripTime();
 			intervalEnd.stripTime();
 		}

+ 13 - 39
src/util.js

@@ -283,38 +283,18 @@ function diffDay(a, b) {
 }
 
 
-// Computes the larges whole-unit period of time, as a duration object.
-// For example, 48 hours will be {days:2} whereas 49 hours will be {hours:49}.
-// Accepts start/end, a range object, or an original duration object.
-/* (never used)
-function computeIntervalDuration(start, end) {
-	var durationInput = {};
-	var i, unit;
-	var val;
-
-	for (i = 0; i < intervalUnits.length; i++) {
-		unit = intervalUnits[i];
-		val = computeIntervalAs(unit, start, end);
-		if (val) {
-			break;
-		}
-	}
-
-	durationInput[unit] = val;
-	return moment.duration(durationInput);
-}
-*/
-
-
 // Computes the unit name of the largest whole-unit period of time.
-// For example, 48 hours will be "days" wherewas 49 hours will be "hours".
+// For example, 48 hours will be "days" whereas 49 hours will be "hours".
 // Accepts start/end, a range object, or an original duration object.
 function computeIntervalUnit(start, end) {
 	var i, unit;
+	var val;
 
 	for (i = 0; i < intervalUnits.length; i++) {
 		unit = intervalUnits[i];
-		if (computeIntervalAs(unit, start, end)) {
+		val = computeRangeAs(unit, start, end);
+
+		if (val >= 1 && isInt(val)) {
 			break;
 		}
 	}
@@ -323,27 +303,21 @@ function computeIntervalUnit(start, end) {
 }
 
 
-// Computes the number of units the interval is cleanly comprised of.
-// If the given unit does not cleanly divide the interval a whole number of times, `false` is returned.
-// Accepts start/end, a range object, or an original duration object.
-function computeIntervalAs(unit, start, end) {
-	var val;
+// Computes the number of units (like "hours") in the given range.
+// Range can be a {start,end} object, separate start/end args, or a Duration.
+// Results are based on Moment's .as() and .diff() methods, so results can depend on internal handling
+// of month-diffing logic (which tends to vary from version to version).
+function computeRangeAs(unit, start, end) {
 
 	if (end != null) { // given start, end
-		val = end.diff(start, unit, true);
+		return end.diff(start, unit, true);
 	}
 	else if (moment.isDuration(start)) { // given duration
-		val = start.as(unit);
+		return start.as(unit);
 	}
 	else { // given { start, end } range object
-		val = start.end.diff(start.start, unit, true);
-	}
-
-	if (val >= 1 && isInt(val)) {
-		return val;
+		return start.end.diff(start.start, unit, true);
 	}
-
-	return false;
 }