@syncfusion/ej2-schedule 27.1.56 → 27.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4039,7 +4039,7 @@ function generate(startDate, rule, excludeDate, startDayOfWeek, maximumCount = M
4039
4039
  dailyType(modifiedDate, ruleObject.until, data, ruleObject);
4040
4040
  break;
4041
4041
  case 'WEEKLY':
4042
- weeklyType(modifiedDate, ruleObject.until, data, ruleObject);
4042
+ weeklyType(modifiedDate, ruleObject.until, data, ruleObject, startDayOfWeek);
4043
4043
  break;
4044
4044
  case 'MONTHLY':
4045
4045
  monthlyType(modifiedDate, ruleObject.until, data, ruleObject);
@@ -4142,10 +4142,11 @@ function dailyType(startDate, endDate, data, ruleObject) {
4142
4142
  * @param {Date} endDate Accepts the end date
4143
4143
  * @param {number[]} data Accepts the collection of dates
4144
4144
  * @param {RecRule} ruleObject Accepts the recurrence rule object
4145
+ * @param {number} startDayOfWeek Accepts the start day index of week
4145
4146
  * @returns {void}
4146
4147
  * @private
4147
4148
  */
4148
- function weeklyType(startDate, endDate, data, ruleObject) {
4149
+ function weeklyType(startDate, endDate, data, ruleObject, startDayOfWeek) {
4149
4150
  let tempDate = new Date(startDate.getTime());
4150
4151
  if (!ruleObject.day.length) {
4151
4152
  ruleObject.day.push(DAYINDEX[startDate.getDay()]);
@@ -4194,7 +4195,7 @@ function weeklyType(startDate, endDate, data, ruleObject) {
4194
4195
  }
4195
4196
  else {
4196
4197
  tempDate = getStartDateForWeek(startDate, ruleObject.day);
4197
- if (interval > 1 && dayIndex.indexOf(ruleObject.day[0]) < startDate.getDay()) {
4198
+ if (interval > 1 && dayIndex.indexOf(ruleObject.day[0]) < (startDate.getDay() - startDayOfWeek)) {
4198
4199
  tempDate.setDate(tempDate.getDate() + ((interval - 1) * 7));
4199
4200
  }
4200
4201
  while (compareDates(tempDate, endDate)) {
@@ -6064,11 +6065,14 @@ class EventBase {
6064
6065
  if (eventsData.length > 0) {
6065
6066
  const selectedObject = eventsData[eventsData.length - 1];
6066
6067
  const eventStartTime = selectedObject[this.parent.eventFields.startTime];
6067
- let nearestTime = new Date(+eventStartTime).setMinutes(0, 0, 0);
6068
+ let nearestTime;
6068
6069
  const isAllDay = this.isAllDayAppointment(selectedObject);
6069
- if (this.parent.currentView === 'Month' || isAllDay) {
6070
+ if (this.parent.currentView === 'Month' || isAllDay || !this.parent.activeViewOptions.timeScale.enable) {
6070
6071
  nearestTime = new Date(+eventStartTime).setHours(0, 0, 0, 0);
6071
6072
  }
6073
+ else {
6074
+ nearestTime = this.findNearestSlot(eventStartTime);
6075
+ }
6072
6076
  let targetArea;
6073
6077
  if (isAllDay && ['Day', 'Week', 'WorkWeek'].indexOf(this.parent.currentView) !== -1) {
6074
6078
  targetArea = this.parent.getAllDayRow();
@@ -6077,7 +6081,8 @@ class EventBase {
6077
6081
  targetArea = this.parent.getContentTable();
6078
6082
  }
6079
6083
  let queryString = '[data-date="' + new Date(nearestTime).getTime() + '"]';
6080
- if (this.parent.activeViewOptions.group.resources.length > 0) {
6084
+ if (!isNullOrUndefined(this.parent.activeViewOptions.group.resources) &&
6085
+ this.parent.activeViewOptions.group.resources.length > 0) {
6081
6086
  queryString += '[data-group-index="' + this.getGroupIndexFromEvent(selectedObject) + '"]';
6082
6087
  }
6083
6088
  target = targetArea.querySelector(queryString);
@@ -6091,6 +6096,25 @@ class EventBase {
6091
6096
  }
6092
6097
  return target;
6093
6098
  }
6099
+ findNearestSlot(appointmentTime) {
6100
+ const msMajorInterval = this.parent.activeViewOptions.timeScale.interval * MS_PER_MINUTE;
6101
+ const msInterval = msMajorInterval / this.parent.activeViewOptions.timeScale.slotCount;
6102
+ const numberOfSlots = Math.round(MS_PER_DAY / msInterval);
6103
+ const startTime = new Date(appointmentTime);
6104
+ startTime.setHours(0, 0, 0, 0);
6105
+ const slots = Array.from({ length: numberOfSlots }, (_, i) => {
6106
+ const slotTime = new Date(startTime.getTime() + i * msInterval);
6107
+ return slotTime;
6108
+ });
6109
+ const nearestSlot = slots.reduce((nearest, slot) => {
6110
+ const difference = Math.abs(appointmentTime.getTime() - slot.getTime());
6111
+ if (!nearest || difference < Math.abs(appointmentTime.getTime() - nearest.getTime())) {
6112
+ return slot;
6113
+ }
6114
+ return nearest;
6115
+ }, null);
6116
+ return Math.trunc(nearestSlot.getTime() / 1000) * 1000;
6117
+ }
6094
6118
  getGroupIndexFromEvent(eventData) {
6095
6119
  let levelIndex;
6096
6120
  let resource;
@@ -6379,7 +6403,7 @@ class EventBase {
6379
6403
  const newTimezone = this.parent.timezone || this.parent.tzModule.getLocalTimezoneName();
6380
6404
  const firstDay = this.parent.activeViewOptions.firstDayOfWeek;
6381
6405
  const calendarMode = this.parent.calendarMode;
6382
- if (event[this.parent.eventFields.recurrenceRule] && event[this.parent.eventFields.recurrenceRule].includes('BYMONTHDAY') &&
6406
+ if (event[this.parent.eventFields.recurrenceRule] && this.isDayBasedRecurrence(event) &&
6383
6407
  this.parent.timezone && event[this.parent.eventFields.startTimezone] && event[this.parent.eventFields.endTimezone]) {
6384
6408
  startDate = this.parent.tzModule.convert(event[this.parent.eventFields.startTime], this.parent.timezone, event[this.parent.eventFields.startTimezone]);
6385
6409
  }
@@ -6399,7 +6423,7 @@ class EventBase {
6399
6423
  }
6400
6424
  let isDSTAdjusted = false;
6401
6425
  let convertedDates = [];
6402
- if (event[this.parent.eventFields.recurrenceRule] && event[this.parent.eventFields.recurrenceRule].includes('BYMONTHDAY') &&
6426
+ if (event[this.parent.eventFields.recurrenceRule] && this.isDayBasedRecurrence(event) &&
6403
6427
  this.parent.timezone && event[this.parent.eventFields.startTimezone] && event[this.parent.eventFields.endTimezone]) {
6404
6428
  isDSTAdjusted = true;
6405
6429
  convertedDates.push(...dates.map((date) => this.parent.tzModule.convert(new Date(date), event[this.parent.eventFields.startTimezone], this.parent.timezone).getTime()));
@@ -6419,6 +6443,10 @@ class EventBase {
6419
6443
  }
6420
6444
  return occurrenceCollection;
6421
6445
  }
6446
+ isDayBasedRecurrence(event) {
6447
+ return (event[this.parent.eventFields.recurrenceRule].includes('BYMONTHDAY')
6448
+ || event[this.parent.eventFields.recurrenceRule].includes('BYDAY'));
6449
+ }
6422
6450
  getDSTAdjustedTime(date, event) {
6423
6451
  let occurDate = date;
6424
6452
  if (this.parent.timezone &&
@@ -28291,10 +28319,12 @@ class Print {
28291
28319
  contentReady() {
28292
28320
  this.printWindow = print$1(this.printInstance.element, this.printWindow);
28293
28321
  this.printWindow.onbeforeunload = () => {
28294
- this.printInstance.off(print, this.contentReady);
28295
- this.printInstance.element.remove();
28296
- this.printInstance.destroy();
28297
- this.printInstance = null;
28322
+ if (this.printInstance) {
28323
+ this.printInstance.off(print, this.contentReady);
28324
+ this.printInstance.element.remove();
28325
+ this.printInstance.destroy();
28326
+ this.printInstance = null;
28327
+ }
28298
28328
  this.printWindow = null;
28299
28329
  };
28300
28330
  }