/**
 * DevExtreme (renovation/ui/scheduler/appointment_edit_form/edit_form/utils/normalizeDate.js)
 * Version: 23.2.4 (build 24056-0112)
 * Build date: Sun Feb 25 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.normalizeNewStartDate = exports.normalizeNewEndDate = void 0;
var _date_serialization = _interopRequireDefault(require("../../../../../../core/utils/date_serialization"));

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
const validateAppointmentFormDate = date => null === date || !!date && !!new Date(date).getDate();
const normalizeNewDate = (newDate, currentDate, currentOppositeDate, needCorrect) => {
    if (!(date = newDate, null === date || !!date && !!new Date(date).getDate())) {
        return currentDate
    }
    var date;
    const normalizedDate = _date_serialization.default.deserializeDate(newDate);
    const normalizedOppositeDate = _date_serialization.default.deserializeDate(currentOppositeDate);
    let result = normalizedDate;
    if (normalizedOppositeDate && normalizedDate && needCorrect(normalizedOppositeDate, normalizedDate)) {
        const duration = normalizedOppositeDate.getTime() - normalizedDate.getTime();
        result = new Date(normalizedDate.getTime() + duration)
    }
    return result
};
const normalizeNewStartDate = (newStartDate, currentStartDate, currentEndDate) => normalizeNewDate(newStartDate, currentStartDate, currentEndDate, (endDate, startDate) => endDate < startDate);
exports.normalizeNewStartDate = normalizeNewStartDate;
const normalizeNewEndDate = (newEndDate, currentStartDate, currentEndDate) => normalizeNewDate(newEndDate, currentEndDate, currentStartDate, (startDate, endDate) => endDate < startDate);
exports.normalizeNewEndDate = normalizeNewEndDate;
