Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

First, reduce the problem to a test of availabilities "per day". All your examples are using ranges for only one day, but if you also want to support a range like "Monday 10:00 to Wednesday 14:00", break this down into three tests for "Monday 10:00 to 23:59", "Thursday 00:00 to 23:59" and "Wednesday 00:00 to 10:00".

For each day, store an interval representation of the available times in form of a list of intervals. Initially, the list contains only one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an different interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

So in terms of sets, all you need is a "subtraction" operation on intervals, a "union" operation, and an overlapping test.

The implementation of the overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See hereSee here for an example. Creating interval unions, or "subtraction" of intervals is not too complicated, too, see heresee here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python. I guess there are similar components or code snippets available for each major programming language, if you don't want to implement this on your own.

First, reduce the problem to a test of availabilities "per day". All your examples are using ranges for only one day, but if you also want to support a range like "Monday 10:00 to Wednesday 14:00", break this down into three tests for "Monday 10:00 to 23:59", "Thursday 00:00 to 23:59" and "Wednesday 00:00 to 10:00".

For each day, store an interval representation of the available times in form of a list of intervals. Initially, the list contains only one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an different interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

So in terms of sets, all you need is a "subtraction" operation on intervals, a "union" operation, and an overlapping test.

The implementation of the overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See here for an example. Creating interval unions, or "subtraction" of intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python. I guess there are similar components or code snippets available for each major programming language, if you don't want to implement this on your own.

First, reduce the problem to a test of availabilities "per day". All your examples are using ranges for only one day, but if you also want to support a range like "Monday 10:00 to Wednesday 14:00", break this down into three tests for "Monday 10:00 to 23:59", "Thursday 00:00 to 23:59" and "Wednesday 00:00 to 10:00".

For each day, store an interval representation of the available times in form of a list of intervals. Initially, the list contains only one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an different interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

So in terms of sets, all you need is a "subtraction" operation on intervals, a "union" operation, and an overlapping test.

The implementation of the overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See here for an example. Creating interval unions, or "subtraction" of intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python. I guess there are similar components or code snippets available for each major programming language, if you don't want to implement this on your own.

added 431 characters in body
Source Link
Doc Brown
  • 220.6k
  • 35
  • 410
  • 625

I assume you can easilyFirst, reduce the problem to a test of availabilities "per day". All your examples are using ranges for only one day, but if you also want to support a range like "Monday 10:00 to Wednesday 14:00", break this down into three tests for "Monday 10:00 to 23:59", "Thursday 00:00 to 23:59" and "Wednesday 00:00 to 10:00".

For each day, usestore an interval representation of the available times in form of a list of intervals. You start withInitially, the list contains only one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an different interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

So in terms of sets, all you need is a "subtraction" operation on intervals, a "union" operation, and an overlapping test.

The implementation of an intervalthe overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See here for an example. An "interval subtraction" for overlappingCreating interval unions, or "subtraction" of intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python, but. I guess there are surely similar components or code snippets available for your favoriteeach major programming language, if you don't want to implement this on your own.

I assume you can easily reduce the problem to a test of availabilities "per day".

For each day, use an interval representation of the available times. You start with one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

The implementation of an interval overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See here for an example. An "interval subtraction" for overlapping intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python, but there are surely similar components available for your favorite programming language, if you don't want to implement this on your own.

First, reduce the problem to a test of availabilities "per day". All your examples are using ranges for only one day, but if you also want to support a range like "Monday 10:00 to Wednesday 14:00", break this down into three tests for "Monday 10:00 to 23:59", "Thursday 00:00 to 23:59" and "Wednesday 00:00 to 10:00".

For each day, store an interval representation of the available times in form of a list of intervals. Initially, the list contains only one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an different interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

So in terms of sets, all you need is a "subtraction" operation on intervals, a "union" operation, and an overlapping test.

The implementation of the overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See here for an example. Creating interval unions, or "subtraction" of intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python. I guess there are similar components or code snippets available for each major programming language, if you don't want to implement this on your own.

added 364 characters in body
Source Link
Doc Brown
  • 220.6k
  • 35
  • 410
  • 625

I assume you can easily reduce the problem to a test of availabilities "per day".

For each day, use an interval representation of the available times. You start with one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

The implementation of an interval overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. it is mentionedSee here, and for an example. An "interval subtraction" for overlapping intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python, but there are probablysurely similar components available for your favorite programming language, if you don't want to implement this on your own.

I assume you can easily reduce the problem to a test of availabilities "per day".

For each day, use an interval representation of the available times. You start with one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

The implementation of an interval overlapping test is not hard, it is mentioned here, and an "interval subtraction" for overlapping intervals is not too complicated, too, see here. At the second link, you will also find a reference to an interval package in Python, but there are probably similar components available for your favorite programming language, if you don't want to implement this on your own.

I assume you can easily reduce the problem to a test of availabilities "per day".

For each day, use an interval representation of the available times. You start with one interval, lets say [9:00 , 17:00] for each day, and whenever a part of the day gets blocked for an interval, (for example, room gets blocked from 10:00 to 11:25), you calculate the new resulting list of intervals (here [9:00,10:00], [11:25, 17:00]). Additional availability leads to additional intervals for some dates, and the "availability check" is nothing but an overlapping test of one new interval with all "available time" intervals of a specific day.

The implementation of an interval overlapping test for two intervals is not hard, it does not require any "sampling", just comparing the minimum and maximum values of each interval. See here for an example. An "interval subtraction" for overlapping intervals is not too complicated, too, see here, note that the "set difference" of two intervals yields either two new intervals, one new interval or zero intervals . At the second link, you will also find a reference to an interval package in Python, but there are surely similar components available for your favorite programming language, if you don't want to implement this on your own.

added 364 characters in body
Source Link
Doc Brown
  • 220.6k
  • 35
  • 410
  • 625
Loading
Source Link
Doc Brown
  • 220.6k
  • 35
  • 410
  • 625
Loading