浏览代码

computeIntervalUnit -> computeGreatestUnit

Adam Shaw 9 年之前
父节点
当前提交
c7a206bd66
共有 3 个文件被更改,包括 8 次插入8 次删除
  1. 1 1
      src/Calendar.js
  2. 2 2
      src/common/View.date-range.js
  3. 5 5
      src/util.js

+ 1 - 1
src/Calendar.js

@@ -149,7 +149,7 @@ var Calendar = FC.Calendar = Class.extend({
 
 			if (duration.valueOf()) { // valid?
 
-				unit = computeIntervalUnit(duration);
+				unit = computeGreatestUnit(duration);
 				if (unit === 'week' && typeof durationInput === 'object' && durationInput.days) {
 					unit = 'day';
 				}

+ 2 - 2
src/common/View.date-range.js

@@ -148,7 +148,7 @@ View.mixin({å
 			range = this.buildRangeFromDayCount(date, direction, dayCount);
 		}
 		else if ((range = this.buildCustomVisibleRange(date))) {
-			unit = computeIntervalUnit(range.start, range.end);
+			unit = computeGreatestUnit(range.start, range.end);
 		}
 		else {
 			unit = 'day';
@@ -181,7 +181,7 @@ View.mixin({å
 
 
 	// Builds the "current" range when it is specified as an explicit duration.
-	// `unit` is the already-computed computeIntervalUnit value of duration.
+	// `unit` is the already-computed computeGreatestUnit value of duration.
 	buildRangeFromDuration: function(date, direction, duration, unit) {
 		var customAlignment = this.opt('dateAlignment');
 		var start = date.clone();

+ 5 - 5
src/util.js

@@ -545,14 +545,14 @@ function intersectRanges(subjectRange, constraintRange) {
 /* Date Utilities
 ----------------------------------------------------------------------------------------------------------------------*/
 
-FC.computeIntervalUnit = computeIntervalUnit; // TODO: rename to greatestUnit or something
+FC.computeGreatestUnit = computeGreatestUnit;
 FC.divideRangeByDuration = divideRangeByDuration;
 FC.divideDurationByDuration = divideDurationByDuration;
 FC.multiplyDuration = multiplyDuration;
 FC.durationHasTime = durationHasTime;
 
 var dayIDs = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ];
-var intervalUnits = [ 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond' ];
+var unitsDesc = [ 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond' ]; // descending
 
 
 // Diffs the two moments into a Duration where full-days are recorded first, then the remaining time.
@@ -585,12 +585,12 @@ function diffByUnit(a, b, unit) {
 // Computes the unit name of the largest whole-unit period of time.
 // 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) {
+function computeGreatestUnit(start, end) {
 	var i, unit;
 	var val;
 
-	for (i = 0; i < intervalUnits.length; i++) {
-		unit = intervalUnits[i];
+	for (i = 0; i < unitsDesc.length; i++) {
+		unit = unitsDesc[i];
 		val = computeRangeAs(unit, start, end);
 
 		if (val >= 1 && isInt(val)) {