UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

67 lines (66 loc) 3.08 kB
/** * DevExtreme (esm/__internal/scheduler/r1/utils/get_appointment_data_items.js) * Version: 24.2.7 * Build date: Mon Apr 28 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { isDefined } from "../../../../core/utils/type"; import { dateUtilsTs } from "../../../core/utils/date"; import { dateUtils } from "../../../core/utils/m_date"; import { createAppointmentAdapter } from "../../m_appointment_adapter"; const RECURRENCE_FREQ = "freq"; const toMs = dateUtils.dateToMilliseconds; export const replaceIncorrectEndDate = (rawAppointment, appointmentDuration, dataAccessors) => { const startDate = new Date(dataAccessors.get("startDate", rawAppointment)); const endDate = new Date(dataAccessors.get("endDate", rawAppointment)); if (!dateUtilsTs.isValidDate(startDate)) { return false } const isEndDateIncorrect = !dateUtilsTs.isValidDate(endDate) || startDate.getTime() > endDate.getTime(); if (isEndDateIncorrect) { const isAllDay = Boolean(dataAccessors.get("allDay", rawAppointment)); const correctedEndDate = isAllDay ? dateUtils.setToDayEnd(new Date(startDate)) : new Date(startDate.getTime() + appointmentDuration * toMs("minute")); dataAccessors.set("endDate", rawAppointment, correctedEndDate) } return true }; export const getAppointmentDataItems = (dataItems, dataAccessors, cellDurationInMinutes, timeZoneCalculator) => { const result = []; null === dataItems || void 0 === dataItems || dataItems.forEach((rawAppointment => { var _recurrenceRule$match; const isAppointmentSafe = replaceIncorrectEndDate(rawAppointment, cellDurationInMinutes, dataAccessors); if (!isAppointmentSafe) { return } const adapter = createAppointmentAdapter(rawAppointment, dataAccessors, timeZoneCalculator); const regex = new RegExp("freq", "gi"); const { recurrenceRule: recurrenceRule } = adapter; const hasRecurrenceRule = Boolean(null === recurrenceRule || void 0 === recurrenceRule || null === (_recurrenceRule$match = recurrenceRule.match(regex)) || void 0 === _recurrenceRule$match ? void 0 : _recurrenceRule$match.length); const visible = isDefined(rawAppointment.visible) ? Boolean(rawAppointment.visible) : true; result.push({ allDay: Boolean(adapter.allDay), startDate: adapter.calculateStartDate("toGrid"), startDateTimeZone: rawAppointment.startDateTimeZone, endDate: adapter.calculateEndDate("toGrid"), endDateTimeZone: rawAppointment.endDateTimeZone, recurrenceRule: recurrenceRule, recurrenceException: adapter.recurrenceException, hasRecurrenceRule: hasRecurrenceRule, visible: visible, rawAppointment: rawAppointment }) })); return result };