Find next available date from a person

142 views Asked by At

So imagine a person has a daily schedule. Each day he has a time range in which he will be available.

{
    "_id": "ObjectId("5570ff8dc7234868035138c9")",
    "name": "John Doe",
    "schedule": [
        {
            "day": 1, // monday
            "from_hour": 10, // time range
            "from_minute": 30,
            "to_hour": 11,
            "to_minute": 0
        },
        {
            "day": 2, // tuesday
            "from_hour": 9, // time range
            "from_minute": 0,
            "to_hour": 12,
            "to_minute": 0
        },
        {
            "day": 5, // friday
            "from_hour": 10, // time range
            "from_minute": 30,
            "to_hour": 11,
            "to_minute": 0
        }
    ]
}

User can add an appointment with the person at an available date. The appointment will look like this.

{
    "_id": "ObjectId("5570ff8dc7234868035138c9")",
    "from_time": "2015-07-15T03:30:00.000Z", // UTC time for Monday, 15-6-2015 10:30
    "to_time": "2015-07-15T04:00:00.000Z" // UTC time for Monday, 15-6-2015 11:00
}

Now, suppose there is another person who wants to find a person's available time slot after a particular date. How can this query be done? I've been thinking of various ways but no results. Please help.

EDIT if anyone has a better schema than this, I'm all ears. This one is all I could think of. Thanks.

0

There are 0 answers