Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

occurences() for rruleset does not respect DTEND #7

Open
GavinRay97 opened this issue Apr 9, 2020 · 0 comments
Open

occurences() for rruleset does not respect DTEND #7

GavinRay97 opened this issue Apr 9, 2020 · 0 comments

Comments

@GavinRay97
Copy link

GavinRay97 commented Apr 9, 2020

The function that consumes an rruleset and returns occurences passes a tsrange instance of (,) by default, which ignores dtend set in in the rruleset.

The following function fixes this:

CREATE OR REPLACE FUNCTION _rrule.occurrences("rruleset" _rrule.RRULESET)
  RETURNS SETOF TIMESTAMP AS $$
DECLARE
  local_rrule _rrule.rrule := rruleset.rrule;
  tsrange_start TIMESTAMP := rruleset.dtstart;
  tsrange_end TIMESTAMP;
  calculated_range TSRANGE;
BEGIN
  IF rruleset.dtend IS NOT NULL THEN
    tsrange_end := rruleset.dtend;
  ELSIF local_rrule.until IS NOT NULL THEN
    tsrange_end = local_rrule.until;
  END IF;

  IF tsrange_end IS NOT NULL THEN
    calculated_range = tsrange(tsrange_start, tsrange_end);
  ELSE
    calculated_range = tsrange(tsrange_start);
  END IF;

  RETURN QUERY SELECT * FROM _rrule.occurrences("rruleset", calculated_range);
END;
$$ LANGUAGE plpgsql IMMUTABLE STRICT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant