Răsfoiți Sursa

fix calendar title incorrectly computed when weekends:false

Adam Shaw 9 ani în urmă
părinte
comite
ad4d451b58
2 a modificat fișierele cu 27 adăugiri și 2 ștergeri
  1. 14 2
      src/common/View.js
  2. 13 0
      tests/automated/titleFormat.js

+ 14 - 2
src/common/View.js

@@ -217,11 +217,23 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
 
 	// Computes what the title at the top of the calendar should be for this view
 	computeTitle: function() {
+		var start, end;
+
+		// for views that span a large unit of time, show the proper interval, ignoring stray days before and after
+		if (this.intervalUnit === 'year' || this.intervalUnit === 'month') {
+			start = this.intervalStart;
+			end = this.intervalEnd;
+		}
+		else { // for day units or smaller, use the actual day range
+			start = this.start;
+			end = this.end;
+		}
+
 		return this.formatRange(
 			{
 				// in case intervalStart/End has a time, make sure timezone is correct
-				start: this.calendar.applyTimezone(this.intervalStart),
-				end: this.calendar.applyTimezone(this.intervalEnd)
+				start: this.calendar.applyTimezone(start),
+				end: this.calendar.applyTimezone(end)
 			},
 			this.opt('titleFormat') || this.computeTitleFormat(),
 			this.opt('titleRangeSeparator')

+ 13 - 0
tests/automated/titleFormat.js

@@ -160,4 +160,17 @@ describe('titleFormat', function() {
             expect($('h2').text()).toMatch(/Dec 25 \- 26\,? 2014/);
         });
     });
+
+    describe('when not all days are shown', function() {
+
+        it('doesn\'t include hidden days in the title', function() {
+            $('#cal').fullCalendar({
+                defaultView: 'agendaWeek',
+                defaultDate: '2017-02-13',
+                weekends: false,
+                titleRangeSeparator: ' - '
+            });
+            expect($('h2')).toHaveText('Feb 13 - 17, 2017'); // does not include Sunday
+        });
+    });
 });