mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-08-29 18:26:05 +00:00
Push the rrule_event_overlaps function into the 8.1 compatibility functions.
This commit is contained in:
parent
b5eeb796dd
commit
093ae24290
@ -652,3 +652,53 @@ BEGIN
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' IMMUTABLE STRICT;
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------
|
||||
-- In most cases we just want to know if there *is* an event overlapping the range, so we have a
|
||||
-- specific function for that. Note that this is *not* strict, and can be called with NULLs.
|
||||
------------------------------------------------------------------------------------------------------
|
||||
CREATE or REPLACE FUNCTION rrule_event_overlaps( TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE, TEXT, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE )
|
||||
RETURNS BOOLEAN AS $$
|
||||
DECLARE
|
||||
dtstart ALIAS FOR $1;
|
||||
dtend ALIAS FOR $2;
|
||||
repeatrule ALIAS FOR $3;
|
||||
in_mindate ALIAS FOR $4;
|
||||
in_maxdate ALIAS FOR $5;
|
||||
base_date TIMESTAMP WITH TIME ZONE;
|
||||
mindate TIMESTAMP WITH TIME ZONE;
|
||||
maxdate TIMESTAMP WITH TIME ZONE;
|
||||
BEGIN
|
||||
|
||||
IF dtstart IS NULL THEN
|
||||
RETURN NULL;
|
||||
END IF;
|
||||
IF dtend IS NULL THEN
|
||||
base_date := dtstart;
|
||||
ELSE
|
||||
base_date := dtend;
|
||||
END IF;
|
||||
|
||||
IF in_mindate IS NULL THEN
|
||||
mindate := current_date - '10 years'::interval;
|
||||
ELSE
|
||||
mindate := in_mindate;
|
||||
END IF;
|
||||
|
||||
IF in_maxdate IS NULL THEN
|
||||
maxdate := current_date + '10 years'::interval;
|
||||
ELSE
|
||||
-- If we add the duration onto the event, then an overlap occurs if dtend <= increased end of range.
|
||||
maxdate := in_maxdate + (base_date - dtstart);
|
||||
END IF;
|
||||
|
||||
IF repeatrule IS NULL THEN
|
||||
RETURN (dtstart <= maxdate AND base_date >= mindate);
|
||||
END IF;
|
||||
|
||||
SELECT d INTO mindate FROM rrule_event_instances_range( base_date, repeatrule, mindate, maxdate, 60 ) d LIMIT 1;
|
||||
RETURN FOUND;
|
||||
|
||||
END;
|
||||
$$ LANGUAGE 'plpgsql' IMMUTABLE;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user