UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

93 lines (92 loc) 4.32 kB
/** * DevExtreme (esm/__internal/scheduler/appointments_new/resizing/get_resized_dates.js) * Version: 26.1.4 * Build date: Fri Jul 24 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import dateUtils from "../../../../core/utils/date"; import timeZoneUtils from "../../utils_time_zone"; const toMs = dateUtils.dateToMilliseconds; export const isStartDateResized = _ref => { let { handles: handles, isVerticalDirection: isVerticalDirection, isAllDay: isAllDay, rtlEnabled: rtlEnabled } = _ref; const usesHorizontalHandles = !isVerticalDirection || isAllDay; if (usesHorizontalHandles) { return rtlEnabled ? handles.right : handles.left } return handles.top }; const correctEndDateByDelta = (endDate, deltaTime, startDayHour, endDayHour) => { const maxDate = new Date(endDate); const minDate = new Date(endDate); const correctEndDate = new Date(endDate); minDate.setHours(startDayHour, 0, 0, 0); maxDate.setHours(endDayHour, 0, 0, 0); if (correctEndDate > maxDate) { correctEndDate.setHours(endDayHour, 0, 0, 0) } let result = correctEndDate.getTime() + deltaTime; const visibleDayDuration = (endDayHour - startDayHour) * toMs("hour"); const daysCount = deltaTime > 0 ? Math.ceil(deltaTime / visibleDayDuration) : Math.floor(deltaTime / visibleDayDuration); if (result > maxDate.getTime() || result <= minDate.getTime()) { const tailOfCurrentDay = maxDate.getTime() - correctEndDate.getTime(); const tailOfPrevDays = deltaTime - tailOfCurrentDay; const correctedEndDate = new Date(correctEndDate).setDate(correctEndDate.getDate() + daysCount); const lastDay = new Date(correctedEndDate); lastDay.setHours(startDayHour, 0, 0, 0); result = lastDay.getTime() + tailOfPrevDays - visibleDayDuration * (daysCount - 1) } return result }; const correctStartDateByDelta = (startDate, deltaTime, startDayHour, endDayHour) => { const maxDate = new Date(startDate); const minDate = new Date(startDate); const correctStartDate = new Date(startDate); minDate.setHours(startDayHour, 0, 0, 0); maxDate.setHours(endDayHour, 0, 0, 0); if (correctStartDate < minDate) { correctStartDate.setHours(startDayHour, 0, 0, 0) } let result = correctStartDate.getTime() - deltaTime; const visibleDayDuration = (endDayHour - startDayHour) * toMs("hour"); const daysCount = deltaTime > 0 ? Math.ceil(deltaTime / visibleDayDuration) : Math.floor(deltaTime / visibleDayDuration); if (result < minDate.getTime() || result >= maxDate.getTime()) { const tailOfCurrentDay = correctStartDate.getTime() - minDate.getTime(); const tailOfPrevDays = deltaTime - tailOfCurrentDay; const firstDay = new Date(correctStartDate.setDate(correctStartDate.getDate() - daysCount)); firstDay.setHours(endDayHour, 0, 0, 0); result = firstDay.getTime() - tailOfPrevDays + visibleDayDuration * (daysCount - 1) } return result }; export const getResizedDates = options => { const { startDate: startDate, endDate: endDate, deltaTime: deltaTime, isStartDateChanged: isStartDateChanged, needCorrectDates: needCorrectDates, startDayHour: startDayHour, endDayHour: endDayHour } = options; if (isStartDateChanged) { const correctedStart = needCorrectDates ? correctStartDateByDelta(startDate, deltaTime, startDayHour, endDayHour) : startDate.getTime() - deltaTime; const startTime = correctedStart + timeZoneUtils.getTimezoneOffsetChangeInMs(startDate, endDate, new Date(correctedStart), endDate); return { startDate: new Date(startTime), endDate: new Date(endDate.getTime()) } } const correctedEnd = needCorrectDates ? correctEndDateByDelta(endDate, deltaTime, startDayHour, endDayHour) : endDate.getTime() + deltaTime; const endTime = correctedEnd - timeZoneUtils.getTimezoneOffsetChangeInMs(startDate, endDate, startDate, new Date(correctedEnd)); return { startDate: new Date(startDate.getTime()), endDate: new Date(endTime) } };