Pārlūkot izejas kodu

open range.start/end can return null, trimHiddenDays can return null, move past hidden days

Adam Shaw 8 gadi atpakaļ
vecāks
revīzija
0ef2193164
4 mainītis faili ar 47 papildinājumiem un 14 dzēšanām
  1. 25 13
      src/DateProfileGenerator.js
  2. 5 1
      src/View.js
  3. 2 0
      src/models/UnzonedRange.js
  4. 15 0
      tests/view-dates/next.js

+ 25 - 13
src/DateProfileGenerator.js

@@ -215,18 +215,11 @@ var DateProfileGenerator = Class.extend({
 	// TODO: accept a MS-time instead of a moment `date`?
 	// TODO: accept a MS-time instead of a moment `date`?
 	buildRangeFromDuration: function(date, direction, duration, unit) {
 	buildRangeFromDuration: function(date, direction, duration, unit) {
 		var alignment = this.opt('dateAlignment');
 		var alignment = this.opt('dateAlignment');
-		var start = date.clone();
-		var end;
 		var dateIncrementInput;
 		var dateIncrementInput;
 		var dateIncrementDuration;
 		var dateIncrementDuration;
-
-		// if the view displays a single day or smaller
-		if (duration.as('days') <= 1) {
-			if (this._view.isHiddenDay(start)) {
-				start = this._view.skipHiddenDays(start, direction);
-				start.startOf('day');
-			}
-		}
+		var start;
+		var end;
+		var res;
 
 
 		// compute what the alignment should be
 		// compute what the alignment should be
 		if (!alignment) {
 		if (!alignment) {
@@ -248,10 +241,29 @@ var DateProfileGenerator = Class.extend({
 			}
 			}
 		}
 		}
 
 
-		start.startOf(alignment);
-		end = start.clone().add(duration);
+		// if the view displays a single day or smaller
+		if (duration.as('days') <= 1) {
+			if (this._view.isHiddenDay(start)) {
+				start = this._view.skipHiddenDays(start, direction);
+				start.startOf('day');
+			}
+		}
+
+		function computeRes() {
+			start = date.clone().startOf(alignment);
+			end = start.clone().add(duration);
+			res = new UnzonedRange(start, end);
+		}
 
 
-		return new UnzonedRange(start, end);
+		computeRes();
+
+		// if range is completely enveloped by hidden days, go past the hidden days
+		if (!this.trimHiddenDays(res)) {
+			date = this._view.skipHiddenDays(date, direction);
+			computeRes();
+		}
+
+		return res;
 	},
 	},
 
 
 
 

+ 5 - 1
src/View.js

@@ -941,6 +941,7 @@ var View = FC.View = InteractiveDateComponent.extend({
 
 
 
 
 	// Remove days from the beginning and end of the range that are computed as hidden.
 	// Remove days from the beginning and end of the range that are computed as hidden.
+	// If the whole range is trimmed off, returns null
 	trimHiddenDays: function(inputUnzonedRange) {
 	trimHiddenDays: function(inputUnzonedRange) {
 		var start = inputUnzonedRange.getStart();
 		var start = inputUnzonedRange.getStart();
 		var end = inputUnzonedRange.getEnd();
 		var end = inputUnzonedRange.getEnd();
@@ -953,7 +954,10 @@ var View = FC.View = InteractiveDateComponent.extend({
 			end = this.skipHiddenDays(end, -1, true);
 			end = this.skipHiddenDays(end, -1, true);
 		}
 		}
 
 
-		return new UnzonedRange(start, end);
+		if (start === null || end === null || start < end) {
+			return new UnzonedRange(start, end);
+		}
+		return null;
 	},
 	},
 
 
 
 

+ 2 - 0
src/models/UnzonedRange.js

@@ -123,6 +123,7 @@ var UnzonedRange = FC.UnzonedRange = Class.extend({
 		if (this.startMs !== null) {
 		if (this.startMs !== null) {
 			return FC.moment.utc(this.startMs).stripZone();
 			return FC.moment.utc(this.startMs).stripZone();
 		}
 		}
+		return null;
 	},
 	},
 
 
 	// Returns an ambig-zoned moment from startMs.
 	// Returns an ambig-zoned moment from startMs.
@@ -132,6 +133,7 @@ var UnzonedRange = FC.UnzonedRange = Class.extend({
 		if (this.endMs !== null) {
 		if (this.endMs !== null) {
 			return FC.moment.utc(this.endMs).stripZone();
 			return FC.moment.utc(this.endMs).stripZone();
 		}
 		}
+		return null;
 	},
 	},
 
 
 
 

+ 15 - 0
tests/view-dates/next.js

@@ -127,4 +127,19 @@ describe('next', function() {
 			});
 			});
 		});
 		});
 	});
 	});
+
+	describe('when in a custom two day view and weekends:false', function() {
+		pushOptions({
+			weekends: false,
+			defaultView: 'agenda',
+			duration: { days: 2 }
+		});
+
+		it('skips over weekends if there would be alignment with weekend', function() {
+			initCalendar({
+				defaultDate: '2017-11-09'
+			});
+			currentCalendar.next();
+		});
+	});
 });
 });