I have a table in the database that stores items that can be rented for several days.
Now that someone is renting an item , they indicate start_date and end_date (basically a date range for which they want to rent this item ).
I want to know what is an efficient algorithm (in terms of time complexity) to verify that the input of date range does not overlap with the existing date ranges in the database.
Illustration:
|<------existing 1------->| |<------existing 2------->| |<------ input date range ---->| (which clearly, overlaps)
Note:
This question is not a duplicate of this question. This checks if the two date ranges overlap. My question is about entering date range overriding several existing date ranges
Another note:
If you are confused by these question tags, I am open to both answers: language-agnostic as well as language-specific .
For those who want to give a language-specific answer, here is more detailed information:
I have a django 1.9 project running on python 3.4 with PostgreSQL as a database. My models:
class Item(models.Model): name = models.CharField(max_length=100) class BookingPeriod(models.Model): item = models.ForeignKey(Item) start_date = models.DateField() end_date = models.DateField()
source share