Sfoglia il codice sorgente

kill getZonedRange

Adam Shaw 8 anni fa
parent
commit
a907b500de

+ 29 - 0
src/Calendar.moment.js

@@ -98,6 +98,35 @@ Calendar.mixin({
 	},
 
 
+	msToMoment: function(ms, forceAllDay) {
+		var mom = FC.moment.utc(ms);
+
+		if (forceAllDay) {
+			mom.stripTime();
+		}
+		else {
+			mom = this.applyTimezone(mom); // may or may not apply locale
+		}
+
+		this.localizeMoment(mom);
+
+		return mom;
+	},
+
+
+	msToUtcMoment: function(ms, forceAllDay) {
+		var mom = FC.moment.utc(ms);
+
+		if (forceAllDay) {
+			mom.stripTime();
+		}
+
+		this.localizeMoment(mom);
+
+		return mom;
+	},
+
+
 	// Updates the given moment's locale settings to the current calendar locale settings.
 	localizeMoment: function(mom) {
 		mom._locale = this.localeData;

+ 6 - 5
src/basic/BasicView.js

@@ -45,19 +45,20 @@ var BasicView = FC.BasicView = View.extend({
 	// Computes the date range that will be rendered.
 	buildRenderRange: function(currentUnzonedRange, currentRangeUnit) {
 		var renderUnzonedRange = View.prototype.buildRenderRange.apply(this, arguments); // an UnzonedRange
-		var zonedRange = renderUnzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
+		var start = this.calendar.msToUtcMoment(renderUnzonedRange.startMs, this.isRangeAllDay);
+		var end = this.calendar.msToUtcMoment(renderUnzonedRange.endMs, this.isRangeAllDay);
 
 		// year and month views should be aligned with weeks. this is already done for week
 		if (/^(year|month)$/.test(currentRangeUnit)) {
-			zonedRange.start.startOf('week');
+			start.startOf('week');
 
 			// make end-of-week if not already
-			if (zonedRange.end.weekday()) {
-				zonedRange.end.add(1, 'week').startOf('week'); // exclusively move backwards
+			if (end.weekday()) {
+				end.add(1, 'week').startOf('week'); // exclusively move backwards
 			}
 		}
 
-		return this.trimHiddenDays(new UnzonedRange(zonedRange.start, zonedRange.end));
+		return this.trimHiddenDays(new UnzonedRange(start, end));
 	},
 
 

+ 5 - 4
src/basic/MonthView.js

@@ -8,18 +8,19 @@ var MonthView = FC.MonthView = BasicView.extend({
 	// Computes the date range that will be rendered.
 	buildRenderRange: function() {
 		var renderUnzonedRange = BasicView.prototype.buildRenderRange.apply(this, arguments);
-		var zonedRange = renderUnzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
+		var start = this.calendar.msToUtcMoment(renderUnzonedRange.startMs, this.isRangeAllDay);
+		var end = this.calendar.msToUtcMoment(renderUnzonedRange.endMs, this.isRangeAllDay);
 		var rowCnt;
 
 		// ensure 6 weeks
 		if (this.isFixedWeeks()) {
 			rowCnt = Math.ceil( // could be partial weeks due to hiddenDays
-				zonedRange.end.diff(zonedRange.start, 'weeks', true) // dontRound=true
+				end.diff(start, 'weeks', true) // dontRound=true
 			);
-			zonedRange.end.add(6 - rowCnt, 'weeks');
+			end.add(6 - rowCnt, 'weeks');
 		}
 
-		return new UnzonedRange(zonedRange.start, zonedRange.end);
+		return new UnzonedRange(start, end);
 	},
 
 

+ 7 - 10
src/common/View.date-range.js

@@ -38,6 +38,8 @@ View.mixin({
 
 
 	setDateProfileForRendering: function(dateProfile) {
+		var calendar = this.calendar;
+
 		this.currentUnzonedRange = dateProfile.currentUnzonedRange;
 		this.currentRangeUnit = dateProfile.currentRangeUnit;
 		this.isRangeAllDay = dateProfile.isRangeAllDay;
@@ -49,14 +51,10 @@ View.mixin({
 		this.maxTime = dateProfile.maxTime;
 
 		// DEPRECATED, but we need to keep it updated...
-
-		var zonedActiveRange = dateProfile.activeUnzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
-		this.start = zonedActiveRange.start;
-		this.end = zonedActiveRange.end;
-
-		var zonedCurrentRange = dateProfile.currentUnzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
-		this.intervalStart = zonedCurrentRange.start;
-		this.intervalEnd = zonedCurrentRange.end;
+		this.start = calendar.msToMoment(dateProfile.activeUnzonedRange.startMs, this.isRangeAllDay);
+		this.end = calendar.msToMoment(dateProfile.activeUnzonedRange.endMs, this.isRangeAllDay);
+		this.intervalStart = calendar.msToMoment(dateProfile.currentUnzonedRange.startMs, this.isRangeAllDay);
+		this.intervalEnd = calendar.msToMoment(dateProfile.currentUnzonedRange.endMs, this.isRangeAllDay);
 	},
 
 
@@ -163,8 +161,7 @@ View.mixin({
 			unzonedRange = this.buildRangeFromDayCount(date, direction, dayCount);
 		}
 		else if ((unzonedRange = this.buildCustomVisibleRange(date))) {
-			var zonedRange = unzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
-			unit = computeGreatestUnit(zonedRange.start, zonedRange.end);
+			unit = computeGreatestUnit(zonedRange.getStart(), zonedRange.getEnd());
 		}
 		else {
 			duration = this.getFallbackDuration();

+ 11 - 12
src/common/View.js

@@ -145,22 +145,20 @@ var View = FC.View = ChronoComponent.extend({
 
 	// Computes what the title at the top of the calendar should be for this view
 	computeTitle: function() {
-		var range;
+		var unzonedRange;
 
 		// for views that span a large unit of time, show the proper interval, ignoring stray days before and after
 		if (/^(year|month)$/.test(this.currentRangeUnit)) {
-			range = this.currentUnzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
+			unzonedRange = this.currentUnzonedRange;
 		}
 		else { // for day units or smaller, use the actual day range
-			range = this.activeUnzonedRange.getZonedRange(this.calendar, this.isRangeAllDay);
+			unzonedRange = this.activeUnzonedRange;
 		}
 
 		return this.formatRange(
 			{
-				// in case currentUnzonedRange has a time, make sure timezone is correct.
-				// TODO: make a utility for zoning an unzoned range.
-				start: this.calendar.applyTimezone(range.start),
-				end: this.calendar.applyTimezone(range.end)
+				start: this.calendar.msToMoment(unzonedRange.startMs, this.isRangeAllDay),
+				end: this.calendar.msToMoment(unzonedRange.endMs, this.isRangeAllDay)
 			},
 			this.isRangeAllDay,
 			this.opt('titleFormat') || this.computeTitleFormat(),
@@ -257,12 +255,13 @@ var View = FC.View = ChronoComponent.extend({
 
 
 	fetchInitialEvents: function(dateProfile) {
-		var zonedRange = dateProfile.activeUnzonedRange.getZonedRange(
-			this.calendar,
-			dateProfile.isRangeAllDay && !this.usesMinMaxTime
-		);
+		var calendar = this.calendar;
+		var forceAllDay = dateProfile.isRangeAllDay && !this.usesMinMaxTime;
 
-		return this.calendar.requestEvents(zonedRange.start, zonedRange.end);
+		return calendar.requestEvents(
+			calendar.msToMoment(dateProfile.activeUnzonedRange.startMs, forceAllDay),
+			calendar.msToMoment(dateProfile.activeUnzonedRange.endMs, forceAllDay)
+		);
 	},
 
 

+ 0 - 19
src/models/UnzonedRange.js

@@ -126,25 +126,6 @@ var UnzonedRange = FC.UnzonedRange = Class.extend({
 
 	getRange: function() {
 		return { start: this.getStart(), end: this.getEnd() };
-	},
-
-	getZonedRange: function(calendar, isAllDay) {
-		var start = FC.moment.utc(this.startMs);
-		var end = FC.moment.utc(this.endMs);
-
-		if (isAllDay) {
-			start.stripTime();
-			end.stripTime();
-		}
-		else if (calendar.getIsAmbigTimezone()) {
-			start.stripZone();
-			end.stripZone();
-		}
-
-		start = calendar.moment(start);
-		end = calendar.moment(end);
-
-		return { start: start, end: end };
 	}
 
 });