Adam Shaw 7 лет назад
Родитель
Сommit
91c69dbdbe
2 измененных файлов с 55 добавлено и 13 удалено
  1. 31 13
      src/DateProfileGenerator.ts
  2. 24 0
      tests/automated/view-dates/dayCount.js

+ 31 - 13
src/DateProfileGenerator.ts

@@ -271,23 +271,41 @@ export default class DateProfileGenerator {
   buildRangeFromDayCount(date, direction, dayCount) {
     let customAlignment = this.opt('dateAlignment')
     let runningCount = 0
-    let start = date.clone()
-    let end
+    let start, end
 
-    if (customAlignment) {
-      start.startOf(customAlignment)
-    }
+    if (customAlignment || direction !== -1) {
 
-    start.startOf('day')
-    start = this._view.skipHiddenDays(start, direction)
+      start = date.clone()
 
-    end = start.clone()
-    do {
-      end.add(1, 'day')
-      if (!this._view.isHiddenDay(end)) {
-        runningCount++
+      if (customAlignment) {
+        start.startOf(customAlignment)
       }
-    } while (runningCount < dayCount)
+
+      start.startOf('day')
+      start = this._view.skipHiddenDays(start)
+
+      end = start.clone()
+      do {
+        end.add(1, 'day')
+        if (!this._view.isHiddenDay(end)) {
+          runningCount++
+        }
+      } while (runningCount < dayCount)
+
+    } else {
+
+      end = date.clone().startOf('day').add(1, 'day')
+      end = this._view.skipHiddenDays(end, -1, true)
+
+      start = end.clone()
+      do {
+        start.add(-1, 'day')
+        if (!this._view.isHiddenDay(start)) {
+          runningCount++
+        }
+      } while (runningCount < dayCount)
+
+    }
 
     return new UnzonedRange(start, end)
   }

+ 24 - 0
tests/automated/view-dates/dayCount.js

@@ -55,4 +55,28 @@ describe('dayCount', function() {
     expectDay('2017-03-26', false) // sun
     expectDay('2017-03-27', true)
   })
+
+  it('can navigate in reverse with a small dateIncrement split by hidden days', function() {
+    initCalendar({
+      defaultDate: '2018-06-11',
+      defaultView: 'agendaTwoDay',
+      header: {
+        left: 'prev,next',
+        center: 'title',
+        right: 'month,agendaWeek,agendaDay,agendaTwoDay'
+      },
+      hiddenDays: [ 0, 6 ],
+      views: {
+        agendaTwoDay: {
+          type: 'agenda',
+          dayCount: 2,
+          dateIncrement: { days: 1 },
+          buttonText: '2 days'
+        }
+      }
+    })
+    currentCalendar.prev()
+    expectActiveRange('2018-06-08', '2018-06-12')
+  })
+
 })