'use strict';

const rangeIncludesDate = require('./rangeIncludesDate.cjs');
const DateLib = require('../classes/DateLib.cjs');

/**
 * Determines if two date ranges overlap.
 *
 * @since 9.2.2
 * @param rangeLeft - The first date range.
 * @param rangeRight - The second date range.
 * @param dateLib - The date utility library instance.
 * @returns `true` if the ranges overlap, otherwise `false`.
 * @group Utilities
 */
function rangeOverlaps(rangeLeft, rangeRight, dateLib = DateLib.defaultDateLib) {
    return (rangeIncludesDate.rangeIncludesDate(rangeLeft, rangeRight.from, false, dateLib) ||
        rangeIncludesDate.rangeIncludesDate(rangeLeft, rangeRight.to, false, dateLib) ||
        rangeIncludesDate.rangeIncludesDate(rangeRight, rangeLeft.from, false, dateLib) ||
        rangeIncludesDate.rangeIncludesDate(rangeRight, rangeLeft.to, false, dateLib));
}

exports.rangeOverlaps = rangeOverlaps;
