Adam Shaw 7 лет назад
Родитель
Сommit
b376827536

+ 0 - 1
karma.config.js

@@ -16,7 +16,6 @@ module.exports = function(config) {
     files: [
 
       // dependencies for main lib
-      'node_modules/moment/moment.js',
       'node_modules/superagent/superagent.js',
       'node_modules/jquery/dist/jquery.js',
       'node_modules/components-jqueryui/jquery-ui.js',

+ 4 - 4
src/Constraints.ts

@@ -134,7 +134,7 @@ export default class Constraints {
         return false
       }
     } else if (typeof overlapVal === 'function') {
-      if (!isOverlapsAllowedByFunc(overlapEventFootprints, overlapVal, subjectEventInstance)) {
+      if (!isOverlapsAllowedByFunc(overlapEventFootprints, overlapVal, subjectEventInstance, this._calendar)) {
         return false
       }
     }
@@ -321,14 +321,14 @@ export default class Constraints {
 
 
 // optional subjectEventInstance
-function isOverlapsAllowedByFunc(overlapEventFootprints, overlapFunc, subjectEventInstance) {
+function isOverlapsAllowedByFunc(overlapEventFootprints, overlapFunc, subjectEventInstance, calendar) {
   let i
 
   for (i = 0; i < overlapEventFootprints.length; i++) {
     if (
       !overlapFunc(
-        overlapEventFootprints[i].eventInstance.toLegacy(this._calendar),
-        subjectEventInstance ? subjectEventInstance.toLegacy(this._calendar) : null
+        overlapEventFootprints[i].eventInstance.toLegacy(calendar),
+        subjectEventInstance ? subjectEventInstance.toLegacy(calendar) : null
       )
     ) {
       return false

+ 13 - 4
tests/automated/globals.js

@@ -118,20 +118,29 @@ window.describeValues = function(hash, callback) {
 
 // Timezone Tests (needed?)
 // ---------------------------------------------------------------------------------------------------------------------
+// NOTE:
+// new Date('YYYY-MM-DD') --- parsed as UTC
+// new Date('YYYY-MM-DDT00:00:00') --- parsed as local
 
 const timezoneScenarios = {
   local: {
     description: 'when local timezone',
     value: 'local',
-    moment: function(str) {
-      return moment(str)
+    date: function(str) {
+      if (str.length <= 10) { // doesn't have a time part?
+        str += 'T00:00:00' // will force it to parse as local
+      }
+      return new Date(str)
     }
   },
   UTC: {
     description: 'when UTC timezone',
     value: 'UTC',
-    moment: function(str) {
-      return moment.utc(str)
+    date: function(str) {
+      if (str.length > 10) { // has a time part?
+        str += 'Z' // will force it to parse as UTC
+      }
+      return new Date(str)
     }
   }
 }

+ 19 - 19
tests/automated/legacy/constraint.js

@@ -664,7 +664,7 @@ describe('selectConstraint', function() {
           start: '2014-11-12T01:00:00',
           end: '2014-11-12T20:00:00'
         }
-        testSelection(options, '03:00', '2014-11-12T10:00:00', true, done)
+        testSelection(options, '2014-11-12T03:00:00Z', '2014-11-12T10:00:00Z', true, done)
       })
     })
 
@@ -676,7 +676,7 @@ describe('selectConstraint', function() {
           start: '2014-11-12T01:00:00',
           end: '2014-11-12T20:00:00'
         }
-        testSelection(options, '01:00', '2014-11-12T05:00:00', true, done)
+        testSelection(options, '2014-11-12T01:00:00Z', '2014-11-12T05:00:00Z', true, done)
       })
     })
 
@@ -688,7 +688,7 @@ describe('selectConstraint', function() {
           start: '2014-11-12T01:00:00',
           end: '2014-11-12T05:00:00'
         }
-        testSelection(options, '03:00', '2014-11-12T05:00:00', true, done)
+        testSelection(options, '2014-11-12T03:00:00Z', '2014-11-12T05:00:00Z', true, done)
       })
     })
 
@@ -700,7 +700,7 @@ describe('selectConstraint', function() {
           start: '2014-11-12T03:00:00',
           end: '2014-11-12T20:00:00'
         }
-        testSelection(options, '02:00', '2014-11-12T04:00:00', false, done)
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-12T04:00:00Z', false, done)
       })
     })
 
@@ -712,7 +712,7 @@ describe('selectConstraint', function() {
           start: '2014-11-12T03:00:00',
           end: '2014-11-12T07:00:00'
         }
-        testSelection(options, '04:00', '2014-11-12T08:00:00', false, done)
+        testSelection(options, '2014-11-12T04:00:00Z', '2014-11-12T08:00:00Z', false, done)
       })
     })
 
@@ -725,7 +725,7 @@ describe('selectConstraint', function() {
             start: '2014-11-12T03:00:00',
             end: '2014-11-12T05:00:00'
           }
-          testSelection(options, '05:00', '2014-11-12T07:00:00', false, done)
+          testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T07:00:00Z', false, done)
         })
       })
       describe('when in month view', function() {
@@ -738,7 +738,7 @@ describe('selectConstraint', function() {
               start: '2014-11-13',
               end: '2014-11-14'
             }
-            testSelection(options, null, '2014-11-14', false, done)
+            testSelection(options, '2014-11-12', '2014-11-14', false, done)
           })
         })
         describe('when a timed constraint, out of bounds', function() {
@@ -749,7 +749,7 @@ describe('selectConstraint', function() {
               start: '2014-11-12T01:00:00',
               end: '2014-11-14T00:00:00'
             }
-            testSelection(options, null, '2014-11-14', false, done)
+            testSelection(options, '2014-11-12', '2014-11-14', false, done)
           })
         })
         describe('when a timed constraint, in bounds', function() {
@@ -760,7 +760,7 @@ describe('selectConstraint', function() {
               start: '2014-11-12T00:00:00',
               end: '2014-11-14T00:00:00'
             }
-            testSelection(options, null, '2014-11-14', true, done)
+            testSelection(options, '2014-11-12', '2014-11-14', true, done)
           })
         })
       })
@@ -777,7 +777,7 @@ describe('selectConstraint', function() {
           start: '01:00:00',
           end: '05:00:00'
         }
-        testSelection(options, '02:00', '2014-11-12T04:00:00', true, done)
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-12T04:00:00Z', true, done)
       })
     })
 
@@ -789,7 +789,7 @@ describe('selectConstraint', function() {
           start: '01:00:00',
           end: '05:00:00'
         }
-        testSelection(options, '02:00', '2014-11-12T06:00:00', false, done)
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-12T06:00:00Z', false, done)
       })
       it('does not allow a selection when multiday', function(done) {
         var options = {}
@@ -798,7 +798,7 @@ describe('selectConstraint', function() {
           start: '01:00:00',
           end: '05:00:00'
         }
-        testSelection(options, '02:00', '2014-11-14T04:00:00', false, done)
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-14T04:00:00Z', false, done)
       })
     })
   })
@@ -814,7 +814,7 @@ describe('selectConstraint', function() {
           end: '05:00:00'
         }
         options.selectConstraint = 'businessHours'
-        testSelection(options, '02:00', '2014-11-12T04:00:00', true, done)
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-12T04:00:00Z', true, done)
       })
     })
 
@@ -827,7 +827,7 @@ describe('selectConstraint', function() {
           end: '05:00:00'
         }
         options.selectConstraint = 'businessHours'
-        testSelection(options, '02:00', '2014-11-12T06:00:00', false, done)
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-12T06:00:00Z', false, done)
       })
     })
 
@@ -841,7 +841,7 @@ describe('selectConstraint', function() {
           dow: [ 1, 2, 4, 5 ] // Mon,Tue,Thu,Fri
         }
         options.selectConstraint = 'businessHours'
-        testSelection(options, '02:00', '2014-11-12T04:00:00', false, done) // Wed
+        testSelection(options, '2014-11-12T02:00:00Z', '2014-11-12T04:00:00Z', false, done) // Wed
       })
     })
   })
@@ -859,7 +859,7 @@ describe('selectConstraint', function() {
           rendering: 'background'
         } ]
         options.selectConstraint = 'yo'
-        testSelection(options, '03:00', '2014-11-12T04:00:00', true, done)
+        testSelection(options, '2014-11-12T03:00:00Z', '2014-11-12T04:00:00Z', true, done)
       })
     })
 
@@ -874,7 +874,7 @@ describe('selectConstraint', function() {
           rendering: 'background'
         } ]
         options.selectConstraint = 'yo'
-        testSelection(options, '03:00', '2014-11-12T06:00:00', false, done)
+        testSelection(options, '2014-11-12T03:00:00Z', '2014-11-12T06:00:00Z', false, done)
       })
     })
 
@@ -884,7 +884,7 @@ describe('selectConstraint', function() {
           var options = {}
 
           options.selectConstraint = 'yooo'
-          testSelection(options, '03:00', '2014-11-12T06:00:00', false, done)
+          testSelection(options, '2014-11-12T03:00:00Z', '2014-11-12T06:00:00Z', false, done)
         })
       })
       describe('when in month view', function() {
@@ -893,7 +893,7 @@ describe('selectConstraint', function() {
 
           options.defaultView = 'month'
           options.selectConstraint = 'yooo'
-          testSelection(options, null, '2014-11-15', false, done)
+          testSelection(options, '2014-11-12', '2014-11-15', false, done)
         })
       })
     })

+ 1 - 6
tests/automated/legacy/dayNames.js

@@ -16,12 +16,7 @@ describe('day names', function() {
   var locales = [ 'es', 'fr', 'de', 'zh-cn', 'nl' ]
 
   pushOptions({
-    now: sundayDate,
-    timezone: 'UTC'
-  })
-
-  afterEach(function() {
-    moment.locale('en') // reset moment's global locale
+    now: sundayDate
   })
 
   testableClasses.forEach(function(viewClass, index, viewClasses) {

+ 32 - 20
tests/automated/legacy/overlap.js

@@ -838,7 +838,7 @@ describe('selectOverlap', function() {
           start: '2014-11-12T04:00:00',
           end: '2014-11-12T06:00:00'
         } ]
-        testSelection(options, '01:00', '2014-11-12T04:00:00', true, done)
+        testSelection(options, '2014-11-12T01:00:00Z', '2014-11-12T04:00:00Z', true, done)
       })
     })
     describe('when dragged adjacently after an event', function() {
@@ -848,29 +848,30 @@ describe('selectOverlap', function() {
           start: '2014-11-12T04:00:00',
           end: '2014-11-12T06:00:00'
         } ]
-        testSelection(options, '06:00', '2014-11-12T12:00:00', true, done)
+        testSelection(options, '2014-11-12T06:00:00Z', '2014-11-12T12:00:00Z', true, done)
       })
     })
     describe('when dragged intersecting an event\'s start', function() {
-      describe('when no timezone', function() {
+      describe('when UTC timezone', function() {
         it('does not allow selection', function(done) {
+          options.timezone = 'UTC'
           options.events = [ {
             title: 'Event A',
-            start: '2014-11-12T04:00:00',
-            end: '2014-11-12T06:00:00'
+            start: '2014-11-12T04:00:00+00:00',
+            end: '2014-11-12T06:00:00+00:00'
           } ]
-          testSelection(options, '01:00', '2014-11-12T05:00:00', false, done)
+          testSelection(options, '2014-11-12T01:00:00Z', '2014-11-12T05:00:00Z', false, done)
         })
       })
-      describe('when UTC timezone', function() {
+      describe('when local timezone', function() {
         it('does not allow selection', function(done) {
-          options.timezone = 'UTC'
+          options.timezone = 'local'
           options.events = [ {
             title: 'Event A',
-            start: '2014-11-12T04:00:00+00:00',
-            end: '2014-11-12T06:00:00+00:00'
+            start: '2014-11-12T04:00:00',
+            end: '2014-11-12T06:00:00'
           } ]
-          testSelection(options, '01:00', '2014-11-12T05:00:00+00:00', false, done)
+          testSelection(options, '2014-11-12T01:00:00', '2014-11-12T05:00:00', false, done)
         })
       })
     })
@@ -883,7 +884,7 @@ describe('selectOverlap', function() {
               start: '2014-11-12T04:00:00',
               end: '2014-11-12T06:00:00'
             } ]
-            testSelection(options, '05:00', '2014-11-12T08:00:00', false, done)
+            testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T08:00:00Z', false, done)
           })
         })
         describe('when UTC timezone', function() {
@@ -894,7 +895,18 @@ describe('selectOverlap', function() {
               start: '2014-11-12T04:00:00+00:00',
               end: '2014-11-12T06:00:00+00:00'
             } ]
-            testSelection(options, '05:00', '2014-11-12T08:00:00+00:00', false, done)
+            testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T08:00:00Z', false, done)
+          })
+        })
+        describe('when local timezone', function() {
+          it('does not allow selection', function(done) {
+            options.timezone = 'local'
+            options.events = [ {
+              title: 'Event A',
+              start: '2014-11-12T04:00:00',
+              end: '2014-11-12T06:00:00'
+            } ]
+            testSelection(options, '2014-11-12T05:00:00', '2014-11-12T08:00:00', false, done)
           })
         })
       })
@@ -909,7 +921,7 @@ describe('selectOverlap', function() {
               start: '2014-11-12',
               end: '2014-11-14'
             } ]
-            testSelection(options, null, '2014-11-13', false, done)
+            testSelection(options, '2014-11-12', '2014-11-13', false, done)
           })
         })
         describe('with timed event', function() {
@@ -919,7 +931,7 @@ describe('selectOverlap', function() {
               start: '2014-11-12T05:00:00',
               end: '2014-11-14T20:00:00'
             } ]
-            testSelection(options, null, '2014-11-13', false, done)
+            testSelection(options, '2014-11-12', '2014-11-13', false, done)
           })
         })
       })
@@ -931,7 +943,7 @@ describe('selectOverlap', function() {
           start: '2014-11-12T04:00:00',
           end: '2014-11-12T10:00:00'
         } ]
-        testSelection(options, '05:00', '2014-11-12T08:00:00', false, done)
+        testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T08:00:00Z', false, done)
       })
     })
   })
@@ -946,7 +958,7 @@ describe('selectOverlap', function() {
           end: '2014-11-12T06:00:00'
         } ]
         spyOn(options, 'selectOverlap').and.callThrough()
-        testSelection(options, '08:00', '2014-11-12T10:00:00', true, function() {
+        testSelection(options, '2014-11-12T08:00:00Z', '2014-11-12T10:00:00Z', true, function() {
           expect(options.selectOverlap).not.toHaveBeenCalled()
           done()
         })
@@ -966,7 +978,7 @@ describe('selectOverlap', function() {
           end: '2014-11-12T06:00:00'
         } ]
         spyOn(options, 'selectOverlap').and.callThrough()
-        testSelection(options, '05:00', '2014-11-12T07:00:00', true, function() {
+        testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T07:00:00Z', true, function() {
           expect(options.selectOverlap).toHaveBeenCalled()
           done()
         })
@@ -983,7 +995,7 @@ describe('selectOverlap', function() {
           end: '2014-11-12T06:00:00'
         } ]
         spyOn(options, 'selectOverlap').and.callThrough()
-        testSelection(options, '05:00', '2014-11-12T07:00:00', false, function() {
+        testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T07:00:00Z', false, function() {
           expect(options.selectOverlap).toHaveBeenCalled()
           done()
         })
@@ -1000,7 +1012,7 @@ describe('selectOverlap', function() {
         end: '2014-11-12T06:00:00',
         overlap: false
       } ]
-      testSelection(options, '05:00', '2014-11-12T07:00:00', true, done)
+      testSelection(options, '2014-11-12T05:00:00Z', '2014-11-12T07:00:00', true, done)
     })
   })
 })

+ 1 - 1
tests/automated/legacy/weekViewRender.js

@@ -1,6 +1,6 @@
 describe('weekViewRender', function() {
 
-  var nowStr = FullCalendar.moment(new Date()).format('YYYY-MM-DD')
+  var nowStr = new Date().toISOString()
 
   pushOptions({
     defaultDate: nowStr,

+ 6 - 2
tests/automated/lib/day-grid.js

@@ -1,7 +1,11 @@
+import { formatIsoDay } from '../datelib/utils'
+
 
 export function getDayGridDayEls(date) {
-  date = FullCalendar.moment.parseZone(date)
-  return $(`.fc-day-grid .fc-day[data-date="${date.format('YYYY-MM-DD')}"]`)
+  if (typeof date === 'string') {
+    date = new Date(date)
+  }
+  return $('.fc-day-grid .fc-day[data-date="' + formatIsoDay(date) + '"]')
 }
 
 

+ 20 - 19
tests/automated/lib/dnd-resize-utils.js

@@ -173,11 +173,8 @@ export function testEventResize(options, resizeDate, expectSuccess, callback, ev
 }
 
 
-// always starts at 2014-11-12
-export function testSelection(options, startTime, end, expectSuccess, callback) {
+export function testSelection(options, start, end, expectSuccess, callback) {
   var successfulSelection = false
-  var calendar
-  var start
   var firstDayEl, lastDayEl
   var firstSlatIndex, lastSlatIndex
   var firstSlatEl, lastSlatEl
@@ -185,25 +182,30 @@ export function testSelection(options, startTime, end, expectSuccess, callback)
   var dragEl
   var allowed
 
+  var isAllDay = false
+  if (typeof start === 'string') {
+    isAllDay = isAllDay || start.indexOf('T') === -1
+    start = new Date(start)
+  }
+  if (typeof end === 'string') {
+    isAllDay = isAllDay || end.indexOf('T') === -1
+    end = new Date(end)
+  }
+
   options.selectable = true
   options.select = function(selectionStart, selectionEnd) {
     successfulSelection =
-      selectionStart.format() === start.format() &&
-        selectionEnd.format() === end.format()
+      selectionStart.valueOf() === start.valueOf() &&
+        selectionEnd.valueOf() === end.valueOf()
   }
   spyOn(options, 'select').and.callThrough()
   initCalendar(options)
 
-  calendar = currentCalendar
-  start = calendar.moment('2014-11-12')
-  end = calendar.moment(end)
-
-  if (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'
-    lastSlatIndex = end.hours() * 2 + (end.minutes() / 30) - 1 // assumes slotDuration:'30:00'
+  if (!isAllDay) {
+    firstDayEl = $('.fc-time-grid .fc-day[data-date="' + formatIsoDay(start) + '"]')
+    lastDayEl = $('.fc-time-grid .fc-day[data-date="' + formatIsoDay(end) + '"]')
+    firstSlatIndex = start.getUTCHours() * 2 + (start.getUTCMinutes() / 30) // assumes slotDuration:'30:00'
+    lastSlatIndex = end.getUTCHours() * 2 + (end.getUTCMinutes() / 30) - 1 // assumes slotDuration:'30:00'
     firstSlatEl = $('.fc-slats tr:eq(' + firstSlatIndex + ')')
     lastSlatEl = $('.fc-slats tr:eq(' + lastSlatIndex + ')')
     expect(firstSlatEl.length).toBe(1)
@@ -211,9 +213,8 @@ export function testSelection(options, startTime, end, expectSuccess, callback)
     dy = lastSlatEl.offset().top - firstSlatEl.offset().top
     dragEl = firstSlatEl
   } else {
-    end.stripTime()
-    firstDayEl = $('.fc-day-grid .fc-day[data-date="' + start.format('YYYY-MM-DD') + '"]')
-    lastDayEl = $('.fc-day-grid .fc-day[data-date="' + end.clone().add(-1, 'day').format('YYYY-MM-DD') + '"]')
+    firstDayEl = $('.fc-day-grid .fc-day[data-date="' + formatIsoDay(start) + '"]')
+    lastDayEl = $('.fc-day-grid .fc-day[data-date="' + formatIsoDay(new Date(end.valueOf() - 1)) + '"]') // inclusive
     dy = lastDayEl.offset().top - firstDayEl.offset().top
     dragEl = firstDayEl
   }

+ 22 - 15
tests/automated/view-render/ViewRenderUtils.js

@@ -1,15 +1,25 @@
+import { formatIsoDay } from '../datelib/utils'
+
 
 export function expectDayRange(start, end) {
-  start = processWholeDay(start)
-  end = processWholeDay(end)
 
-  var dayBefore = start.clone().subtract(1, 'day')
+  if (typeof start === 'string') {
+    expect(start.indexOf('T')).toBe(-1)
+    start = new Date(start)
+  }
+
+  if (typeof end === 'string') {
+    expect(end.indexOf('T')).toBe(-1)
+    end = new Date(end)
+  }
+
+  var dayBefore = FullCalendar.addDays(start, -1)
   expectDay(dayBefore, false)
 
-  var date = start.clone()
+  var date = start
   while (date < end) { // eslint-disable-line
     expectDay(date, true)
-    date.add(1, 'day')
+    date = FullCalendar.addDays(date, 1)
   }
 
   // `date` is now the first day after the range
@@ -18,8 +28,13 @@ export function expectDayRange(start, end) {
 
 
 export function expectDay(date, bool) {
-  date = processWholeDay(date)
-  var els = $('td.fc-day[data-date="' + date.format() + '"]')
+
+  if (typeof date === 'string') {
+    expect(date.indexOf('T')).toBe(-1)
+    date = new Date(date)
+  }
+
+  var els = $('td.fc-day[data-date="' + formatIsoDay(date) + '"]')
 
   if (bool) {
     expect(els).toBeInDOM()
@@ -27,11 +42,3 @@ export function expectDay(date, bool) {
     expect(els).not.toBeInDOM()
   }
 }
-
-
-function processWholeDay(date) {
-  date = FullCalendar.moment.parseZone(date)
-  expect(date.hasTime()).toBe(false)
-  expect(date.hasZone()).toBe(false)
-  return date
-}