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

Detecting Overlapping Events #5

Open
switchtower opened this issue May 29, 2014 · 3 comments
Open

Detecting Overlapping Events #5

switchtower opened this issue May 29, 2014 · 3 comments

Comments

@switchtower
Copy link

Curious if you ever thought of adding a check in the form clean method to check for overlapping occurrences with the rrules being used in the submitted form?

Thanks for the great code!

@kvps
Copy link

kvps commented Dec 9, 2014

Is there a way to handle this with current code? I am having the same situation.
Thanks!!!

@rfj001
Copy link

rfj001 commented Dec 14, 2014

Here's what I am doing... I cloned the repo and modified the source directly to add a method to the OccurrenceManager class, but you could just write a function that takes two occurrences, or subclass occurrence.

def occurrence_at_time_exists(self, start, end, occurrence_set=None):
        if not occurrence_set:
            occurrence_set = Occurrence.objects.all()
        occurrence_set.filter(start_time__lte=start, end_time__gte=start)
        overlaps = occurrence_set.filter(
            models.Q(start_time__lte=start, end_time__gt=start) |
            models.Q(start_time__gte=start, start_time__lt=end) |
            models.Q(start_time=start, end_time=end)
        ).exists()
        return overlaps

Note that this implementation returns False if one occurrence begins at the same time that the other ends. For example, if I have an occurrence from 9:00-10:00 and another from 10:00-11:00 this would not interpret them as overlapping.

@kvps
Copy link

kvps commented Dec 17, 2014

Thanks. I am working more modifications on swingtime code, this really helps. Thanks again!!!

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

3 participants