Преглед изворни кода

moment's timeDuration -> time

Adam Shaw пре 11 година
родитељ
комит
9229523474

+ 2 - 2
src/EventManager.js

@@ -641,10 +641,10 @@ function EventManager(options) { // assumed to be a calendar
 						end = null;
 
 						if (startTime) {
-							start = start.timeDuration(startTime);
+							start = start.time(startTime);
 						}
 						if (endTime) {
-							end = date.clone().timeDuration(endTime);
+							end = date.clone().time(endTime);
 						}
 
 						event = $.extend({}, abstractEvent); // make a copy of the original

+ 4 - 4
src/common/TimeGrid.js

@@ -85,7 +85,7 @@ $.extend(TimeGrid.prototype, {
 
 		// Calculate the time for each slot
 		while (slotTime < this.maxTime) {
-			slotDate = view.start.clone().timeDuration(slotTime); // will be in UTC but that's good. to avoid DST issues
+			slotDate = view.start.clone().time(slotTime); // will be in UTC but that's good. to avoid DST issues
 			minutes = slotDate.minutes();
 
 			axisHtml =
@@ -145,8 +145,8 @@ $.extend(TimeGrid.prototype, {
 
 		for (col = 0; col < view.colCnt; col++) {
 			cellDate = view.cellToDate(0, col); // use the View's cell system for this
-			colStart = cellDate.clone().timeDuration(this.minTime);
-			colEnd = cellDate.clone().timeDuration(this.maxTime);
+			colStart = cellDate.clone().time(this.minTime);
+			colEnd = cellDate.clone().time(this.maxTime);
 			seg = intersectionToSeg(rangeStart, rangeEnd, colStart, colEnd);
 			if (seg) {
 				seg.col = col;
@@ -210,7 +210,7 @@ $.extend(TimeGrid.prototype, {
 
 		return calendar.rezoneDate( // since we are adding a time, it needs to be in the calendar's timezone
 			view.cellToDate(0, cell.col) // View's coord system only accounts for start-of-day for column
-				.timeDuration(this.minTime + this.snapDuration * cell.row)
+				.time(this.minTime + this.snapDuration * cell.row)
 		);
 	},
 

+ 2 - 2
src/common/View.js

@@ -316,7 +316,7 @@ View.prototype = {
 
 						// if dropped on an all-day cell, and element's metadata specified a time, set it
 						if (meta.startTime && !eventStart.hasTime()) {
-							eventStart.timeDuration(meta.startTime);
+							eventStart.time(meta.startTime);
 						}
 
 						// trigger 'drop' regardless of whether element represents an event
@@ -833,7 +833,7 @@ function View(calendar) {
 
 		if (end) {
 			endDay = end.clone().stripTime(); // the beginning of the day the range exclusively ends
-			endTimeMS = +end.timeDuration(); // # of milliseconds into `endDay`
+			endTimeMS = +end.time(); // # of milliseconds into `endDay`
 
 			// If the end time is actually inclusively part of the next day and is equal to or
 			// beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.

+ 10 - 2
src/moment-ext.js

@@ -134,7 +134,14 @@ newMomentProto.clone = function() {
 // SETTER
 // You can supply a Duration, a Moment, or a Duration-like argument.
 // When setting the time, and the moment has an ambiguous time, it then becomes unambiguous.
-newMomentProto.timeDuration = function(time) {
+newMomentProto.time = function(time) {
+
+	// Fallback to the original method (if there is one) if this moment wasn't created via FullCalendar.
+	// `time` is a generic enough method name where this precaution is necessary to avoid collisions w/ other plugins.
+	if (!this._fullCalendar) {
+		return oldMomentProto.time.apply(this, arguments);
+	}
+
 	if (time == null) { // getter
 		return moment.duration({
 			hours: this.hours(),
@@ -376,7 +383,8 @@ function transferAmbigs(src, dest) {
 }
 
 
-// Sets the year/month/date/etc values of the moment from the given array
+// Sets the year/month/date/etc values of the moment from the given array.
+// Inefficient because it calls each individual setter.
 function setMomentValues(mom, a) {
 	mom.year(a[0] || 0)
 		.month(a[1] || 0)

+ 1 - 1
src/util.js

@@ -258,7 +258,7 @@ var dayIDs = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ];
 function dayishDiff(a, b) {
 	return moment.duration({
 		days: a.clone().stripTime().diff(b.clone().stripTime(), 'days'),
-		ms: a.timeDuration() - b.timeDuration()
+		ms: a.time() - b.time()
 	});
 }
 

+ 3 - 3
tests/automated/moment-ambig.js

@@ -88,7 +88,7 @@ describe('ambiguously-timed moment', function() {
 
 	it('has a zero time', function() {
 		var mom = $.fullCalendar.moment.parseZone('2014-06-08');
-		var time = mom.timeDuration();
+		var time = mom.time();
 		expect(+time).toBe(0);
 	});
 
@@ -116,9 +116,9 @@ describe('ambiguously-timed moment', function() {
 		var mom = $.fullCalendar.moment.parseZone('2014-06-08');
 		expect(mom.hasTime()).toBe(false);
 		var time = moment.duration({ hours: 1, minutes: 25 });
-		mom.timeDuration(time);
+		mom.time(time);
 		expect(mom.hasTime()).toBe(true);
-		expect(+mom.timeDuration()).toBe(+time);
+		expect(+mom.time()).toBe(+time);
 	});
 
 	it('can be given a time and zone via utc', function() {

+ 7 - 7
tests/automated/moment-misc.js

@@ -7,13 +7,13 @@ describe('FCMoment::time', function() {
 
 		it('should return 00:00 for a moment with 00:00 time', function() {
 			var mom = $.fullCalendar.moment.utc('2014-06-08T00:00:00');
-			var time = mom.timeDuration();
+			var time = mom.time();
 			expect(time).toEqualDuration('00:00');
 		});
 
 		it('should return the time of a moment with a time', function() {
 			var mom = $.fullCalendar.moment.utc('2014-06-08T07:30:00');
-			var time = mom.timeDuration();
+			var time = mom.time();
 			expect(time).toEqualDuration('07:30');
 		});
 	});
@@ -28,21 +28,21 @@ describe('FCMoment::time', function() {
 			it('should give a moment with 00:00 a time', function() {
 				var mom = $.fullCalendar.moment.utc('2014-06-08T00:00:00');
 				var dur = moment.duration('13:25');
-				mom.timeDuration(dur);
+				mom.time(dur);
 				expect(mom).toEqualMoment('2014-06-08T13:25:00+00:00');
 			});
 
 			it('should overwrite the time of a moment with a time', function() {
 				var mom = $.fullCalendar.moment.utc('2014-06-08T05:00:00');
 				var dur = moment.duration('13:25');
-				mom.timeDuration(dur);
+				mom.time(dur);
 				expect(mom).toEqualMoment('2014-06-08T13:25:00+00:00');
 			});
 
 			it('should move to next day if greater than 24 hours', function() {
 				var mom = $.fullCalendar.moment.utc('2014-06-08T00:00:00');
 				var dur = moment.duration('1.01:00:00'); // 1 day, 1 hour
-				mom.timeDuration(dur);
+				mom.time(dur);
 				expect(mom).toEqualMoment('2014-06-09T01:00:00+00:00');
 			});
 		});
@@ -52,14 +52,14 @@ describe('FCMoment::time', function() {
 			it('should give a moment with 00:00 a time', function() {
 				var mom1 = $.fullCalendar.moment.utc('2014-06-09T00:00:00');
 				var mom2 = $.fullCalendar.moment.utc('2014-07-22T05:30:00'); // a Tues, so .days() -> 2
-				mom1.timeDuration(mom2);
+				mom1.time(mom2);
 				expect(mom1).toEqualMoment('2014-06-09T05:30:00+00:00');
 			});
 
 			it('should overwrite the time of a moment with a time', function() {
 				var mom1 = $.fullCalendar.moment.utc('2014-06-09T04:15:00');
 				var mom2 = $.fullCalendar.moment.utc('2014-07-22T05:30:00'); // a Tues, so .days() -> 2
-				mom1.timeDuration(mom2);
+				mom1.time(mom2);
 				expect(mom1).toEqualMoment('2014-06-09T05:30:00+00:00');
 			});
 		});

+ 2 - 2
tests/automated/updateEvent.js

@@ -218,7 +218,7 @@ describe('updateEvent', function() {
 				{ id: '1', start: '2014-05-10', end: '2014-05-13', allDay: true }
 			];
 			init();
-			event.start.timeDuration('18:00');
+			event.start.time('18:00');
 			$('#cal').fullCalendar('updateEvent', event);
 			expect(event.allDay).toEqual(false);
 			expect(event.start).toEqualMoment('2014-05-01T18:00:00');
@@ -255,7 +255,7 @@ describe('updateEvent', function() {
 				];
 				init();
 				event.allDay = false;
-				event.start.timeDuration('14:00');
+				event.start.time('14:00');
 				$('#cal').fullCalendar('updateEvent', event);
 				expect(event.allDay).toEqual(false);
 				expect(event.start).toEqualMoment('2014-05-01T14:00:00');

+ 1 - 1
tests/lib/dnd-resize-utils.js

@@ -174,7 +174,7 @@ function testSelection(options, startTime, end, expectSuccess, callback) {
 	end = calendar.moment(end);
 
 	if (startTime) {
-		start.timeDuration(startTime);
+		start.time(startTime);
 		firstDayEl = $('.fc-time-grid .fc-day[data-date="' + start.format('YYYY-MM-DD') + '"]');
 		lastDayEl = $('.fc-time-grid .fc-day[data-date="' + end.format('YYYY-MM-DD') + '"]');
 		firstSlatIndex = start.hours() * 2 + (start.minutes() / 30); // assumes slotDuration:'30:00'